繁体   English   中英

PHP邮件功能不起作用

[英]PHP mail function not working

我已经为邮件功能编写了基本脚本。 我正在尝试通过WAMP服务器运行此脚本。

<?php
phpinfo();

$to = "mss@xyz.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "mohan.s@xyz.com";
$headers = "From: $from";
$res= mail($to,$subject,$message,$headers);
echo " $res Mail Sent.";
?> 

我已经在php.ini文件中设置了SMTP,sendmail_from。 它给我以下错误

警告:mail()[function.mail]:无法通过“ mucse409.eu.xyz.com”端口25连接到邮件服务器,无法在php.ini中验证“ SMTP”和“ smtp_port”设置,或在C语言中使用ini_set() :第9行的\\\\ wamp \\ www \\ email.php已发送邮件。

我可以从我的计算机ping SMTP地址。 请指导我。

您还可以使用某些邮件客户端(例如ms Outlook或mozilla thunderbird)将邮件从本机发送到此smtp服务器吗?

一旦我的提供程序由于病毒感染而阻止了指向外部smtp端口的流量时出现了一个问题,因此我无法发送邮件,但是我可以ping服务器和端口。

可能被防火墙等阻止。

看看是否可以使用telnet打开端口25(如果没有与此相关的软件,则可以下载腻子)

遵循本教程,我能够发送邮件链接文本

使用Gmail和PHPMailer发送电子邮件新的自动更新生成器已经准备就绪,距离OCRALight已经完成很长时间了,而其中的一点点工作已经在更新生成中得到了完善。

这个过程相当复杂,涉及到逆向工程,数据挖掘,打包,分发,并且要与我们和最终的Linux解放之间的笨拙的Windows服务器作斗争。

流程中的每一步都一步一步实现了自动化,每个问题都得到了解决和完善,现在最后一步就在他的位置,自动生成电子邮件。 现在将进行更新,并每天,甚至在周末和假期发送。

如果您对技术方面感兴趣,请继续阅读:

如何完成的:

首先,您需要具有支持OpenSSL的PHP​​,对于Windows,您需要安装PHP并在组件列表中仔细选择OpenSSL,如果您已经安装了PHP,请不要担心重新安装会保持您的配置,然后您可以选择OpenSSL。

然后下载PHPMailer,&nbsp; 并将其解压缩到您的主要php文件附近。

您将需要拥有一个Gmail帐户(显然),我建议您为此新建一个帐户,主要是因为配置必须非常精确,并且您将无法自由使用它,而不会失去功能或冒着以下风险:破坏配置。

将您的Gmail帐户配置为使用POP邮件,但不使用IMAP,仅使用POP,仅使用POP。

现在的代码:

<?php
require(”PHPMailer/class.phpmailer.php”);
$update_emails = array(
    ‘Juan Perez’ => ‘Juan_Perez@jalisco.gob.mx’,
    ‘Francisco Garcia’ => ‘fgarcia@hotmail.com’,
    ‘Diana la del Tunel’ => ‘diana@gmail.com’
  );

echo “\nSending Update Email\n”;

$mail = new PHPMailer();  // Instantiate your new class
$mail->IsSMTP();          // set mailer to use SMTP
$mail->SMTPAuth = true;   // turn on SMTP authentication
$mail->Host = “smtp.gmail.com”; // specify main and backup server
$mail->SMTPSecure= ’ssl’; //  Used instead of TLS when only POP mail is selected
$mail->Port = 465;        //  Used instead of 587 when only POP mail is selected

$mail->Username = “youremail@gmail.com”;  // SMTP username, you could use your google apps address too.
$mail->Password = “yaourextremelynotlamepassword”; // SMTP password

$mail->From = “youremail@gmail.com”; //Aparently must be the same as the UserName
$mail->FromName = “Your name”;
$mail->Subject = ‘The subject’;
$mail->Body = “The body of your message”;

foreach ($update_emails as $name => $email) {
  $mail->AddBcc($email, $name);
}

if(!$mail->Send())
{
  echo “There was an error sending the message:” . $mail->ErrorInfo;
  exit;
}
echo “Done…\n”;
?>

在此代码中,我将电子邮件发送给一群人,因此,我使用“密件抄送:”字段而不是“收件人:”字段来添加“收件人:”,您将使用AddAddress($ email,$ name)。

可能的升级是使用MySQL数据库存储地址, 并提供一个Web界面来添加和删除它们。 目前,这已经足够。

还记得:PHP和OpenSSL; PHPMailer; 创建一个Gmail帐户; 激活POP主机:smtp.gmail.com; SMTPAuth = true; SMTPSEcure = ssl; 端口:465; 具有域的用户; 密码; $ Mail-&gt; send();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM