我有此错误消息。你能帮我吗?
我的email.php;
<?php
header('Content-Type: text/html; charset=utf-8');
require 'PHPMailerAutoload.php';
$phpmailer = new PHPMailer;
$phpmailer->isSMTP();
$phpmailer->Host = 'mail.coffeewritingcontent.com';
$phpmailer->SMTPAuth = true;
$phpmailer->Username = 'iletisim@coffeewritingcontent.com';
$phpmailer->Password = 'mypassword';
$phpmailer->SMTPSecure = 'tls';
$phpmailer->Port = '587';
$phpmailer->From = 'iletisim@coffeewritingcontent.com';
$phpmailer->FromName = $_POST['name'];
$phpmailer->AddReplyTo($_POST['email'], $_POST['name']);
$phpmailer->addAddress('iletisim@coffeewritingcontent.com', 'İletişim Formu');
$phpmailer->isHTML(true);
$phpmailer->Subject = 'İletisim formu mesajı';
$phpmailer->Body = "isim: " . $_POST['name'] . "\r\n\r\nMesaj: " . stripslashes($_POST['message']);
$phpmailer->CharSet = 'UTF-8';
$phpmailer->SMTPDebug = 4;
if(!$phpmailer->send()) {
echo 'Mail gonderilemedi. Hata: ' . $phpmailer->ErrorInfo;
exit;
}
echo 'Mail gonderildi.';
?>
我的错误;
2016-03-26 21:52:59连线:开场 mail.coffeewritingcontent.com:587,timeout = 10,options = array() 2016-03-26 21:53:09 SMTP错误:无法连接到服务器: 连接超时(110)邮件gonderilemedi。错误:语言字符串 无法加载:connect_host
答案 0 :(得分:0)
请尝试此代码。我现在在GoDaddy的服务器上使用,一切顺利。请确保要求php库包含require_once实例
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'localhost'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'mymail@mydomain.com'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 25; // TCP port to connect to
$mail->setFrom('mymail@mydomain.com', 'Name');
$mail->addAddress($email);
$mail->isHTML(true);
$mail->setLanguage('es');
$mail->CharSet = 'UTF-8';
$mail->Subject = 'Welcome!';
$mail->Body = 'This is a messagge test!';
if ( !$mail->send() ) :
echo 'Error while sending mail.';
else :
echo 'The messagge send correctly';
endif;
答案 1 :(得分:-1)
您在创建所有这些代码之前是否创建了$ phpmailer 的瞬间?可能你必须这样做。所以,如果你已经这样做了,请查看你的文件PHPMailerAutoload.php并确保你的文件夹中有phpmailer在下载内容后提供给我们的所有和完整文件。我将向您展示一个从phpmailer发送电子邮件的正确代码的示例。
require_once('../class.phpmailer.php');
$mail = new PHPMailer(); // defaults to using php "mail()"
$body = file_get_contents('contents.html');
$body = eregi_replace("[\]",'',$body);
$mail->AddReplyTo("name@yourdomain.com","First Last");
$mail->SetFrom('name@yourdomain.com', 'First Last');
$mail->AddReplyTo("name@yourdomain.com","First Last");
$address = "whoto@otherdomain.com";
$mail->AddAddress($address, "John Doe");
$mail->Subject = "PHPMailer Test Subject via mail(), basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$mail->AddAttachment("images/phpmailer.gif"); // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
请确保您从已上传的服务器发送电子邮件。如果您使用的是XAMPP等虚拟服务,请查看此页面以启用smtp配置:How to configure XAMPP to send mail from localhost?
问候。