PHP邮件程序不在cpanel上工作

PHP邮件程序不在cpanel上工作,php,email,localhost,phpmailer,cpanel,Php,Email,Localhost,Phpmailer,Cpanel,我的php邮件程序在localhost上运行良好,但当我在cpanel上运行相同的代码时,会收到错误消息:SMTP connect()失败 请帮助我,我哪里出错了?您可能忘记启用对您的GMail帐户的SMTP访问(这是设置中IMAP访问的一部分) 而且,”tls://smtp.gmail.com“不是有效的SMTP服务器地址。使用$mail->SMTPSecure=“tls”如果您想使用TLS。您可能忘记启用对GMail帐户的SMTP访问(这是设置中IMAP访问的一部分) 而且,”tls:/

我的php邮件程序在localhost上运行良好,但当我在cpanel上运行相同的代码时,会收到错误消息:SMTP connect()失败



请帮助我,我哪里出错了?

您可能忘记启用对您的GMail帐户的SMTP访问(这是设置中IMAP访问的一部分)


而且,”tls://smtp.gmail.com“不是有效的SMTP服务器地址。使用
$mail->SMTPSecure=“tls”如果您想使用TLS。

您可能忘记启用对GMail帐户的SMTP访问(这是设置中IMAP访问的一部分)


而且,”tls://smtp.gmail.com“不是有效的SMTP服务器地址。使用
$mail->SMTPSecure=“tls”如果您想使用TLS。

谢谢您的建议,非常感谢:-)

我得到的解决方案如下

1>give Absolute path for PHPMailerAutoload.php
2>host name as "localhost"
3>create dummy emailId on server



<?php
require'/home/username/public_html/phpmailertesting/PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->SMTPDebug =3;                               // Enable verbose debug output
$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'localhost';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'info@hostname.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->setFrom('info@hostname.com', 'Mailer');
$mail->addAddress('*******@gmail.com');               // Name is optional
 //$mail->addReplyTo('info@hostname.com', 'Information');
 //$mail->addCC('*******@gmail.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;
exit();
} else {
echo 'Message has been sent';
}
?>
1>给出phpmailerautoad.php的绝对路径
2> 主机名为“localhost”
3> 在服务器上创建虚拟电子邮件ID

谢谢您的建议,非常感谢:-)

我得到的解决方案如下

1>give Absolute path for PHPMailerAutoload.php
2>host name as "localhost"
3>create dummy emailId on server



<?php
require'/home/username/public_html/phpmailertesting/PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->SMTPDebug =3;                               // Enable verbose debug output
$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'localhost';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'info@hostname.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->setFrom('info@hostname.com', 'Mailer');
$mail->addAddress('*******@gmail.com');               // Name is optional
 //$mail->addReplyTo('info@hostname.com', 'Information');
 //$mail->addCC('*******@gmail.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;
exit();
} else {
echo 'Message has been sent';
}
?>
1>给出phpmailerautoad.php的绝对路径
2> 主机名为“localhost”
3> 在服务器上创建虚拟电子邮件ID

CPanel默认情况下阻止对外部SMTP服务器的访问

在whm>安全中心>SMTP限制禁用中禁用此限制

这很有效

<?php
require_once('./class.phpmailer.php');
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages                         only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "smtp.mail.yahoo.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "xxxxxx@ymail.com";
$mail->Password = "xxxxxx";
$mail->SetFrom("xxxxx@ymail.com");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("xxxxx@ymail.com");

if(!$mail->Send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message has been sent";
}?>

CPanel默认情况下阻止对外部SMTP服务器的访问

在whm>安全中心>SMTP限制禁用中禁用此限制

这很有效

<?php
require_once('./class.phpmailer.php');
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages                         only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "smtp.mail.yahoo.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "xxxxxx@ymail.com";
$mail->Password = "xxxxxx";
$mail->SetFrom("xxxxx@ymail.com");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("xxxxx@ymail.com");

if(!$mail->Send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message has been sent";
}?>

您需要从ISP公司购买Cpanel/WHM,以便访问外部SMTP电子邮件,如Gmail。首先,禁用:WHM>安全中心>SMTP限制已禁用。
并确保CSF防火墙已启用“SMTP_块”设置。 如果您在安全设置中使用Gmail,则可以启用较少的安全性,您可以使用smtp验证。
PHPMailer建议对所有防火墙和安全问题使用SSL。

您需要从ISP公司购买Cpanel/WHM,以便能够访问外部SMTP电子邮件,如Gmail。首先,禁用:WHM>安全中心>SMTP限制已禁用。
并确保CSF防火墙已启用“SMTP_块”设置。 如果您在安全设置中使用Gmail,则可以启用较少的安全性,您可以使用smtp验证。
PHPMailer建议对所有防火墙和安全问题使用SSL。

如果您注释掉对
addAddress
的调用,消息不会发送给任何人,那么您为什么希望它工作?!您可以尝试从收到的错误消息中链接。但是,在取消注释$mail->AddAddress()时,它给出了一个错误:SMTP connect()失败您甚至无法尝试发送如果您没有设置收件人,并不是设置收件人导致连接错误!您是否已验证您的Cpanel计算机已为OUT打开端口587?“SMTP错误:无法连接到SMTP主机。”这也可能显示为SMTP connect()失败或在调试输出中未连接而调用了Mail()。这通常被报告为PHPMailer问题,但几乎总是由于本地DNS故障、防火墙阻塞或本地网络上的其他问题。这意味着PHPMailer无法联系您在主机属性中指定的SMTP服务器,但没有确切说明原因。如果您注释掉对
addAddress
的调用,则消息不会发送给任何人,那么您为什么希望它工作?!您可以尝试从收到的错误消息中链接。但是,在取消注释$mail->AddAddress()时,它给出了一个错误:SMTP connect()失败您甚至无法尝试发送如果您没有设置收件人,并不是设置收件人导致连接错误!您是否已验证您的Cpanel计算机已为OUT打开端口587?“SMTP错误:无法连接到SMTP主机。”这也可能显示为SMTP connect()失败或在调试输出中未连接而调用了Mail()。这通常被报告为PHPMailer问题,但几乎总是由于本地DNS故障、防火墙阻塞或本地网络上的其他问题。这意味着PHPMailer无法联系您在主机属性中指定的SMTP服务器,但没有确切说明原因@DestylioHarsha好吧,这是个开始。请参阅我的最新答案。show$mail->Host='smtp.gmail.com'@DestylioHarsha好吧,这是个开始。请参阅我的最新答案。show$mail->Host='smtp.gmail.com';