我有一个PHPMailer脚本,并且我已经检查了与此类似的所有其他线程,并尝试了所有问题后面的解决方案。但这是我收到的错误
2014-01-03 02:25:16 SMTP ERROR: Failed to connect to server: Connection timed out (110) SMTP connect() failed. Mailer Error: SMTP connect() failed.
这是我的剧本:
$body = "test";
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // I have also tried tls
$mail->SMTPKeepAlive = true;
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // I have also tried 25
$mail->Username = "xxxx@gmail.com"; // GMAIL username
$mail->Password = "xxxxx"; // GMAIL password
$mail->SetFrom("johndoe@gmail.com","John Doe");
$mail->AddReplyTo("johndoe@gmail.com","John Doe");
$mail->Subject = "Booking from " . $_POST['person'] . ' at ' . $_POST['name'];
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$address = "johndoe@hotmail.co.uk";
$mail->AddAddress($address, "John Doe");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
但是我无法让它发挥作用。我尝试了很多不同的解决方案。我甚至乐意使用默认的php邮件,但我只需要它发送,php邮件甚至无法通过hotmail垃圾邮件过滤器(我的意思是它甚至没有发送它垃圾邮件)。
这里有任何解决方案或建议吗?非常感谢!
答案 0 :(得分:0)
您确定您的实时服务器和本地主机服务器上的php.ini邮件设置是否相同?
答案 1 :(得分:0)
从
安装PHP邮件程序https://github.com/Synchro/PHPMailer
阅读“一个简单的例子”
<?php
require_once('PHPMailer/PHPMailerAutoload.php'); // Load your PHPMailerAutoload.php Correctly Here
$mail = new PHPMailer;
//$mail->SMTPDebug = 3;// debugging: 1 = errors and messages, 2 = messages only // 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; // Enable SMTP authentication
$mail->Username = 'yourmail@gmail.com'; // SMTP username
$mail->Password = '**********'; // SMTP password
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // or 587 // TCP port to connect to
$mail->setFrom('fromemail@gmail.com', 'Vijay Rami');
$mail->addAddress('toemail@gmail.com', 'Vijay Rami'); // Add a recipient
//$mail->addAddress('ellen@example.com'); // Name is optional
//$mail->addReplyTo('info@example.com', 'Information');
//$mail->addCC('cc@example.com');
//$mail->addBCC('bcc@example.com');
//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
//$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
答案 2 :(得分:0)
只需评论此行:
$mail->IsSMTP();