By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,286 Members | 2,443 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,286 IT Pros & Developers. It's quick & easy.

Trouble sending email using php form

P: 6
Hi I am going crazy trying to send an email using XAMPP, my php form on my localhost server.

This is the email section of the code

Expand|Select|Wrap|Line Numbers
  1. if($insert_result)
  2.         {    
  3.  
  4.             ini_set('SMTP', 'ssl://smtp.gmail.com');
  5.             ini_set('smtp_port', 465); 
  6.             ini_set('sendmail_from', 'myemail@gmail.com');
  7.             ini_set('sendmail_path', 'localhost\C:\Program Files\xampp\sendmail\sendmail.exe');$to = $_REQUEST['email'];
  8.             $message = "Please fill out a survey form. Follow this link---> <a href='{$email_link}'>HERE</a> to load the form.<br>";
  9.             $nameTo = "Dear User"; 
  10.             $subject = "Form completion required!";
  11.             $headers = "MIME-Version: 1.0" . '\r\n';
  12.             $headers .= "Content-type: text/html; charset=iso-8859-1" . '\r\n';
  13.             $headers .= "From: myemail@gmail.com" . '\r\n';
  14.  
  15.             $sent = mail($to, $subject, $message, $headers) ; 
  16.             if($sent) 
  17.             {print "Your mail was sent successfully"; }
  18.             else 
  19.             {print "We encountered an error sending your mail";
  20.             echo $message;
  21.             phpinfo();
  22.             }
  23.  
Right now, I am trying to use gmail's SMTP server. And it gives the following error:

Warning: mail() [function.mail]: Failed to connect to mailserver at "ssl://smtp.gmail.com" port 465, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\xampp\htdocs\survey.php on line 328

I modified the sendmail.ini and entered my username and password in the auth_username and auth_password fields and restarted XAMPP. No result.

Earlier I tried sending using my company's ISP server. But it says Client is not authenticated.

I printed phpinfo() to check whats wrong. Its using the same php.ini file I am modifying and the local values of SMTP and smtp_port are changing but not the master values.

Mercury is running in my XAMPP Control Panel. Do I need to setup mercury? I just can't figure this out. I really hope someone can help me sort this out ASAP. Much appreciated.
Jun 29 '12 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 1,035
change line 4 to:
Expand|Select|Wrap|Line Numbers
  1. ini_set('SMTP', 'smtp.gmail.com'); 
  2.  
This is because PHP does not know how to do 'ssl://', and thats why it says "Failed to connect to mailserver at "ssl://smtp.gmail.com" port ......"
Jul 1 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.