无法使用外部smtp服务器在php中发送邮件

时间:2013-04-08 23:26:30

标签: php windows smtp

我正在尝试使用下面的php脚本从外部smtp服务器发送邮件,

<?php
$recipient="john_doe@gmail.com"; 
$subject="Website to customer";
$message="Customer Name: ".$_POST['name']."\r\n";
$message.="Customer Email: ".$_POST['email']."\r\n";
$message.="Customer Message: ".$_POST['msg']."\r\n"; 
$mailheader="From: <maria@comcast.net> \r\n";
$mailheader.="Reply to ".$_POST['email'];
ini_set("SMTP","comcast.net");
mail($recipient, $subject, $message, $mailheader);
?>
<!DOCTYPE html>
<html>
<head>
<title>Sending mail from website to Customer</title>
</head>
<body>
<p>Thanks, <strong><?php echo $_POST['name']; ?></strong>, for your message.</p>
<p>Your email address: <strong><?php echo $_POST['email']; ?></strong></p>
<p>Your message: <br/><?php echo $_POST['msg']; ?></p>
</body>
<html>

我收到错误消息:

Warning: mail() [function.mail]: Failed to connect to mailserver at "comcast.net" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\sendmail.php on line 10

是因为我没有本地电子邮件服务器吗? phpmailer会解决我的问题吗?有人能引导我走向正确的方向吗?非常感谢。

2 个答案:

答案 0 :(得分:2)

呀。谷歌5秒钟发现了这个,http://customer.comcast.com/help-and-support/internet/list-of-blocked-ports/

使用端口465.您可能需要设置帐户信息以便在其服务器上发送传出信息。

答案 1 :(得分:1)

使用smtp.comcast.net代替comcast.net作为SMTP参数。将smtp_port参数设为587 但是页面[2]表明您需要SMTP AUTHentication,而不是由php-mail支持。有关可用的替代方案,请参见第[3]页。

<强> URL(S):
1. http://www.php.net/manual/en/mail.configuration.php
2. http://customer.comcast.com/help-and-support/internet/email-client-programs-with-xfinity-email/
3. php.ini & SMTP= - how do you pass username & password