为什么我不能使用我的本地域发送电子邮件,但如果我使用gmail,它将成功发送到localhost

时间:2016-08-31 07:16:35

标签: php email

为什么我无法在localhost中使用我的域发送电子邮件?但是,当我使用gmail smtp时,它已成功发送电子邮件(在localhost中)

这是使用debug = 4的错误:

2016-08-31 07:08:05 Connection: opening to ssl://mail.mydomain.com:443, timeout=300, options=array ( ) 2016-08-31 07:08:05  Connection: opened

这是我的代码

require 'PHPMailer/PHPMailerAutoload.php';

$mail = new PHPMailer;

$mail->isSMTP();                                   // Set mailer to use SMTP
$mail->Host = 'mail.mydomain.mncgroup.com';                    // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                            // Enable SMTP authentication
$mail->Username = 'emailsender@mydomain.com';         // SMTP username
$mail->Password = 'pass';                   // SMTP password
$mail->SMTPSecure = 'ssl';                         // Enable TLS encryption, `ssl` also accepted
$mail->Port = 443;  
$mail->SMTPDebug=4;

$mail->setFrom('emailsender@mydomain.com', 'a');
$mail->addReplyTo('emailsender@mydomain.com', 'a');

$mail->addAddress('myemail.mydomain.com');   // Add a recipient
//$mail->addCC('cc@example.com');
//$mail->addBCC('bcc@example.com');

$mail->isHTML(true);  // Set email format to HTML



$mail->Subject = 'Reminder ';
$mail->Body    = $bodyContent;

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;

} else {
    echo 'Message has been sent';
}

1 个答案:

答案 0 :(得分:0)

从localhost发送邮件的可能性较小,因为它需要SMTP服务器,默认情况下不会安装。因此,您无法直接从本地发送邮件。 有解决方案:

  1. 在本地安装SMTP服务器。
  2. 使用第三方SMTP服务器。 (您正在使用GMAIL)
  3. 如果您使用第二个解决方案,请通过以下链接

    http://www.mittalpatel.co.in/php_send_mail_from_localhost_using_gmail_smtp