Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Mar 2012
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    sending email from php script

    I am using Windows Server 2003 Enterprise Edition. On this server, I have configured SMTP. While configuring SMTP, I have provided gmail.com in one of the fields.
    I have following two files on Windows Server 2003 Enterprise Edition. phpTest2.html
    Code:
    <html>
    	<head>
    	</head>
    
    	<body>
    		<h2>Alien Abduction Form</h2>
    		<form action="phpTest2.php" method="POST">
    			When It Happened :<input type="text" name="whenithappened" /><br />
    			How  Long :<input type="text" name="howlong" /><br />
    			<input type="submit" value="submit" /><br />
    		</form>
    	</body>
    </html>
    phpTest2.php
    Code:
    <html>
    	<head>
    	</head>
    
    	<body>
    		<?php
    			$when_it_happened = $_POST['whenithappened'];
    			$how_long = $_POST['howlong'];
    			$to = 'testmail2012@gmail.com';
    			$subject = 'PHP Test';
    			$msg = $when_it_happened.$how_long ;
    			mail($to, $subject, $msg);
    			echo "your message is received";
    		?>
    	</body>
    </html>
    When I send data using form in phpTest2.html and invoke phpTest2.php, I get the message "your message is received" on my screen. So I assume that message has been sent. But when I check gmail account, I dont see any emails there.

    Before configuring SMTP, when I used this script, I was getting an error message that SMTP i not set up. But now, I am not getting this message any more and I am not getting emails in specified gmail acccount. So whats wrong in here ?

    Thanks

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    You say you've setup smtp and used gmail. How have you setup smtp? in your php.ini file? Using fakesendmail? PHPMailer?

    You need to give us more detail. What you've said is crystal clear to you but for us it covers very little.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #3
    New Coder
    Join Date
    Mar 2012
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    Following is mail function section of php.ini
    Code:
    [Phar]
    ; http://php.net/phar.readonly
    ;phar.readonly = On
    
    ; http://php.net/phar.require-hash
    ;phar.require_hash = On
    
    ;phar.cache_list =
    
    [Syslog]
    ; Whether or not to define the various syslog variables (e.g. $LOG_PID,
    ; $LOG_CRON, etc.).  Turning it off is a good idea performance-wise.  In
    ; runtime, you can define these variables by calling define_syslog_variables().
    ; http://php.net/define-syslog-variables
    define_syslog_variables  = Off
    
    [mail function]
    ; For Win32 only.
    ; http://php.net/smtp
    SMTP = localhost
    ; http://php.net/smtp-port
    smtp_port = 25
    
    ; For Win32 only.
    ; http://php.net/sendmail-from
    sendmail_from = you@yourdomain
    
    ; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
    ; http://php.net/sendmail-path
    ;sendmail_path =
    
    ; Force the addition of the specified parameters to be passed as extra parameters
    ; to the sendmail binary. These parameters will always replace the value of
    ; the 5th parameter to mail(), even in safe mode.
    ;mail.force_extra_parameters =
    
    ; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
    mail.add_x_header = On
    
    ; Log all mail() calls including the full path of the script, line #, to address and headers
    ;mail.log =
    
    [SQL]
    ; http://php.net/sql.safe-mode
    sql.safe_mode = Off
    I checked on the net about php.ini and settings in my php.ini is exactly the way described in there.

    Please let me know what changes are required and why is this not working if no changes are needed.



    Thanks
    Last edited by jigneshjsoni; 05-27-2012 at 10:57 PM.

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    Again, you're not providing enough information. You've just said no to php.ini and asked what to do with it. You've not answered my questions about fakesendmail, PHPMailer etc.

    PHP has no native SMTP support yet you claim you've configured SMTP. What have you configured? - Is it a SMTP server that is based on your machine?

    If thats what you've done then PHP will need to be able to connect to it. For that you would need to use one of two options:

    Fakesendmail (which comes with its own instructions to guide you through installation OR PHPMailer - a php class you can find via google that will connect to a SMTP server.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #5
    New Coder
    Join Date
    Mar 2012
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [mail function]
    ; For Win32 only.
    ; http://php.net/smtp
    SMTP = smtphm.sympatico.ca
    ;SMTP = localhost
    ; http://php.net/smtp-port
    smtp_port = 25

    ; For Win32 only.
    ; http://php.net/sendmail-from
    sendmail_from = you@yourdomain
    This is my configuration for php.ini

    I have done nothing with fakesendmail or PHPMailer or anything else. I dont know what is that.

    Before I had configuration as SMTP = localhost. Now, I have configured SMTP = smtphm.sympatico.ca. Now I am getting warning message as follows.
    Warning: mail() [function.mail]: SMTP server response: 530 5.7.0 Must issue a STARTTLS command first in C:\Documents and Settings\Administrator\Desktop\doc\phpTest2.php on line 12
    I have configured sendmail.ini as follows
    [sendmail]

    ; you must change mail.mydomain.com to your smtp server
    ; smtp.amis.net smtp.volja.net

    ; smtp_server=localhost

    smtp_server=smtphm.sympatico.ca

    ; the default domain for this server will be read from the registry
    ; this will be appended to email addresses when one isn't provided
    ; if you want to override the value in the registry, uncomment and modify

    ; default_domain=exampledomain.com

    default_domain=207.164.234.193

    ; log smtp errors to error.log (defaults to same directory as sendmail.exe)
    ; uncomment to enable logging

    error_logfile=error.log

    ; create debug log as debug.log (defaults to same directory as sendmail.exe)
    ; uncomment to enable debugging

    debug_logfile=debug.log

    ; if your smtp server requires authentication, uncomment and modify the
    ; following two lines

    ;auth_username=
    ;auth_password=

    auth_username=abc@bell.net
    auth_password=secret

    ; if your smtp server uses pop3 before smtp authentication, uncomment and
    ; modify the following three lines

    ;pop3_server=
    ;pop3_username=
    ;pop3_password=
    Is this info sufficient ? Please let me know, if any more info is needed
    Can you say whats wrong with this script with current configuration ?

    Thanks
    Last edited by jigneshjsoni; 05-29-2012 at 06:19 AM.

  • #6
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    As mentioned before, PHP (while the .ini file suggests it has SMTP support) doesn't really come with SMTP support (the php.ini file may look that way but as you've just found out it's not great).

    Instead download fakesendmail OR PHPMailer as I've previously suggested. As previously explained, fakesendmail comes with its own instructions and PHPMailer is a php class that you include in your php script. IT supports sentmail, SMTP, and I think imap but I'm not 100% on that.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #7
    New Coder
    Join Date
    Mar 2012
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have also attached sendmail.ini

    I downloaded sendmail and installed it. I have attached sendmail.ini in above post. Is this sendmail.ini configuration not enough ?

    If sendmail.ini is good enough for sending mails, please let me know, whats wrong with configuration I have provided in here.

    Thanks

  • #8
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    Why are you updating the last post and then adding a new post below? - Thats weird. When you have something new to add do it in a new post don't go back and edit an older post because it gets confusing trying to keep up with it all.

    You need to post php.ini again and also your sendmail configuration please. IF you do it in a nice new post it will be easier to understand and follow.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •