使用php通过SMTP gmail发送电子邮件

时间:2017-05-04 14:57:10

标签: php smtp

我收到了这个错误

无法发送消息。邮件程序错误:SMTP连接()失败。https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

$mail = new PHPMailer;
$mail->IsSMTP();                                   
$mail->Host = 'smtp.gmail.com';                    
$mail->SMTPAuth = true;                            
$mail->Username = '*****';         
$mail->Password = '*****';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->SetFrom('*****', 'Innovatory');
$mail->AddAddress($f1_email);
$mail->isHTML(true);
$bodyContent = '<br><h3>From: '.$f1_fname.'</h3>';
$bodyContent .= '<b>Company Name: '.$f1_subject.'<br>Mobile: '.$f1_phone.'<br>Email: '.$f1_email.'</b><br><br><b>Service:</b> '.$f1_message;

$mail->Subject = 'Contact Email';
$mail->Body    = $bodyContent;
$mail->mailer="smtp";
if(!$mail->send())
{
    echo 'Message could not be sent. ';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
}
else 
{
    ?>
    <script>
    alert('Mail has been sent.');
    window.location.href='index.php';
    </script>
    <?php
}

0 个答案:

没有答案