Hi All,
I wanted to send mail in php and as i do not have any mail server at home so i googled for free smtp server which i can configure and use in PHP.
I am facing problem in sending a mail using PHPMailer.
I wanted to verify the mail functionality before giving to somebody else for execution.
Below I am providing the environment details where the PHP is installed in my local system.
I am using laptop with internet connection(via data card).
OS:- Windows 7
Web Server:- IIS 7
PHP Ver:- 5.6.0
Below is the smtp configuration in
php.ini and also extension=php_openssl.dll is uncommented in php.ini file:-
[mail function]
; For Win32 only.
; [url]http://php.net/smtp
SMTP = localhost
; [url]http://php.net/smtp-port
smtp_port = 25
; For Win32 only.
; [url]http://php.net/sendmail-from
;sendmail_from = [email][email protected]
[ExtensionList]
extension=php_mysql.dll
extension=php_mysqli.dll
extension=php_mbstring.dll
extension=php_gd2.dll
extension=php_gettext.dll
extension=php_curl.dll
extension=php_exif.dll
extension=php_xmlrpc.dll
extension=php_openssl.dll
extension=php_soap.dll
extension=php_pdo_mysql.dll
extension=php_pdo_sqlite.dll
extension=php_imap.dll
extension=php_tidy.dll
Mail Functionality
PHPMailerAutoload.php
class.phpmailer.php
class.pop3.php
class.smtp.php
All the above files are in the same directory where email.php(shown at below) is there.
File Name:- [url]http://localhost/PHPMail/email.php
<?php
require(“PHPMailerAutoload.php”);
$email = “
$message = “This is the mail from PHPMailer.” ;
$mail = new PHPMailer();
// set mailer to use SMTP
$mail->IsSMTP();
$mail->SMTPDebug = 1;
// As this email.php script lives on the same server as our email server
// we are setting the HOST to localhost
$mail->Host = “ssl://smtp.gmail.com”; // specify main and backup server
$mail->Port = 465;//port
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPSecure = ‘SSL’; // secure transfer enabled REQUIRED for GMail
// When sending email using PHPMailer, you need to send from a valid email address
// In this case, we setup a test email account with the following credentials:
// email: [email][email protected]
// pass: password
$mail->Username = “
$mail->Password = “********”; // SMTP password
// $email is the user’s email address the specified
// on our contact us page. We set this variable at
// the top of this page with:
// $email = $_REQUEST[’email’] ;
$mail->From = $email;
// below we want to set the email address we will be sending our email to.
$mail->AddAddress(“
// set word wrap to 50 characters
$mail->WordWrap = 50;
// set email format to HTML
$mail->IsHTML(true);
$mail->Subject = “You have received feedback from your website!”;
$mail->Body = $message;
if(!$mail->Send())
{
echo “Message could not be sent. <p>”;
echo “Mailer Error: ” . $mail->ErrorInfo;
exit;
}
echo “Message has been sent”;
?>
I am getting the error messages for different SMTP Host and port configurations.
1.
$mail->Host = “ssl://smtp.gmail.com”;
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->SMTPSecure = ‘SSL’;
Error Message:-
SMTP -> ERROR: Failed to connect to server: (0)
SMTP Error: Could not connect to SMTP host. Message could not be sent.
Mailer Error: SMTP Error: Could not connect to SMTP host.
2.
$mail->Host = “smtp.gmail.com”;
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->SMTPSecure = ‘TLS’;
Error Message:-
SMTP -> ERROR: AUTH not accepted from server: 530 5.7.0 Must issue a STARTTLS command first. 2sm15315794pdp.68 – gsmtp
SMTP Error: Could not authenticate. Message could not be sent.
Mailer Error: SMTP Error: Could not authenticate.
3.
$mail->Host = “smtpout.secureserver.net”;
$mail->Port = 80;
$mail->SMTPAuth = true;
$mail->SMTPSecure = ”;
SMTP -> ERROR: Password not accepted from server: 535 Authentication Failed for [email][email protected]
SMTP -> ERROR: RSET failed:
SMTP Error: Could not authenticate. Message could not be sent.
Mailer Error: SMTP Error: Could not authenticate.
SMTP server error:
Kindly assist me in resolving this issue.
Thanks & Regards,
[email][email protected]