有人可以帮助我吗? 我需要使用php发送电子邮件。
我正在使用此代码发送邮件
<?php
error_reporting(E_ALL); ini_set('display_errors', '1');
require '/PHPMailer-master/PHPMailerAutoload.php';
error_reporting(E_ALL); ini_set('display_errors', '1');
echo (extension_loaded('openssl')?'SSL loaded':'SSL not loaded')."\n";
$mail = new PHPMailer;
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true;
$mail->SMTPDebug = true; // Enable SMTP authentication
$mail->Username = 'email@gmail.com'; // SMTP username
$mail->Password = '******'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->From = $_POST['email'];
$mail->FromName = 'Mailer';
$mail->addAddress('email@gmail.com', 'Joe User');
$mail->IsHTML(false); // Set email format to HTML
$message = $_POST['message'];
$mail->Subject = $_POST['subject'];
$mail->Body = preg_replace('/\[\]/','',$message);
$mail->AltBody = 'This is a plain-text message body';
if(!$mail->Send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
归来总是这样。
SSL loaded 2015-06-02 19:05:41 Connection: opening to smtp.gmail.com:465, timeout=300, options=array ( ) 2015-06-02 19:09:56 SMTP ERROR: Failed to connect to server: Network is unreachable (101) 2015-06-02 19:09:56 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
我正在使用PHPMailer。 我已经阅读了https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting,但没有任何变化。