Reputation:
I am using XAMPP on windows 7 but I'm unable to send mail using php
The php.ini file part is as under:
SMTP = smtp.gmail.com
smtp_port = 25
sendmail_from = hima***ivast***@gmail.com
sendmail_path = "C:\xampp\sendmail\sendmail.exe -t"
mail.add_x_header = Off
The sendmail.ini file part is as under:
smtp_server=smtp.gmail.com
smtp_port=25
error_logfile=error.log
debug_logfile=debug.log
auth_username=hima***ivast***@gmail.com
auth_password=************
force_sender=hima***ivast***@gmail.com
Please help me find the error.
Upvotes: 0
Views: 525
Reputation: 21191
If you have SSL enabled on the Gmail account, port number is 587. I believe the other is 465, as per the help docs: https://support.google.com/mail/answer/78775?hl=en
If you tried configuring your SMTP server on port 465 (with SSL) and port 587 (with TLS), but are still having trouble sending mail, try configuring your SMTP to use port 25 (with SSL).
You should probably also be using a try/catch block - if sendmail is failing with an error, you can print_r or var_dump to see what the exception message contains.
I should admit I haven't ever used sendmail directly; I found the Rmail library a lot easier to use:
<?php
require_once( ROOT . DS . "libs" . DS . "Rmail" . DS . "Rmail.php" );
// Instantiate a new HTML Mime Mail object
$mail = new Rmail();
$mail->setSMTPParams($host = 'smtp.gmail.com', $port = 587, $helo = null, $auth = true, $user = 'gmail address', $pass = 'password');
// Set the From and Reply-To headers
$mail->setFrom( "Proper Name <send from email address>" );
$mail->setReturnPath( "reply email address" );
// Set the Subject
$mail->setSubject( 'Email subject/title' );
$html = 'you email message content';
// Create the HTML e-mail
$mail->setHTML( $html );
// Send the e-mail
$result = $mail->send( array( 'target email address' ) );
?>
I can track down the library somewhere if you'd rather use something like the snippet above.
Upvotes: 0