我正在使用PHPMailer发送电子邮件。当我使用gmail smtp时它工作正常,但当我尝试使用我的域smtp时,我在屏幕上看到的是“发送消息!”#39;但我根本没有收到任何电子邮件。我试过使用调试器,它说
We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
这是我的代码
<?php
date_default_timezone_set('Etc/UTC');
//Load PHPMailer dependencies
require_once 'PHPMailerAutoload.php';
require_once 'class.phpmailer.php';
require_once 'class.smtp.php';
/* CONFIGURATION */
$crendentials = array(
'email' => 'xxxxx@example.com',
'password' => 'xxxxxx'
);
$smtp = array(
'host' => 'secure.ehostpk.com',
'port' => 465,
'username' => $crendentials['email'],
'password' => $crendentials['password'],
'secure' => 'ssl' //SSL or TLS
);
/* TO, SUBJECT, CONTENT */
$to = 'xxxxxx@example.com'; //The 'To' field
$subject = 'This is a test email sent with PHPMailer';
$content = 'This is the HTML message body <b>in bold!</b>';
$mailer = new PHPMailer();
//SMTP Configuration
$mailer->isSMTP();
$mailer->SMTPDebug = 2;
$mailer->SMTPAuth = true; //We need to authenticate
$mailer->Host = $smtp['host'];
$mailer->Port = $smtp['port'];
$mailer->Username = $smtp['username'];
$mailer->Password = $smtp['password'];
$mailer->SMTPSecure = $smtp['secure'];
//Now, send mail :
//From - To :
$mailer->From = $crendentials['email'];
$mailer->FromName = 'Team'; //Optional
$mailer->addAddress($to); // Add a recipient
//Subject - Body :
$mailer->Subject = $subject;
$mailer->Body = $content;
$mailer->isHTML(true); //Mail body contains HTML tags
//Check if mail is sent :
if(!$mailer->send()) {
echo 'Error sending mail : ' . $mailer->ErrorInfo;
} else {
echo 'Message sent !';
}
我经常搜索,但我不知道该怎么做。任何帮助将不胜感激。
答案 0 :(得分:0)
我发现的一件事是,在大多数服务器上(特别是cpanel服务器),您尝试发送的电子邮件地址实际上必须在cpanel中创建,以使其正常工作。
根据我的理解,脚本只会将其路由到服务器和电子邮件帐户,然后从那里进一步路由,最后从服务器上的电子邮件帐户发送出去。因此,解决方案可能是在服务器中实际设置电子邮件地址。