可能重复:
使用Gmail 的PHP邮件
代码:
<?
//change this to your email.
$to = "bhavesh412@gmail.com";
$from = "bhavesh412@gmail.com";
$subject = "Hello! This is HTML email";
//begin of HTML message
$message = <<<EOF
<html>
<body bgcolor="#DCEEFC">
<center>
<b>Looool!!! I am reciving HTML email......</b> <br>
<font color="red">Thanks Mohammed!</font> <br>
<a href="http://www.maaking.com/">* maaking.com</a>
</center>
<br><br>*** Now you Can send HTML Email <br> Regards<br>MOhammed Ahmed - Palestine
</body>
</html>
EOF;
//end of message
$headers = "From: $from'r'n";
$headers .= "Content-type: text/html'r'n";
//options to send to cc+bcc
//$headers .= "Cc: [email]maa@p-i-s.cXom[/email]";
//$headers .= "Bcc: [email]email@maaking.cXom[/email]";
// now lets send the email.
ini_set("SMTP","smtp.gmail.com");
ini_set("smtp_port","465");
mail($to, $subject, $message, $headers);
echo "Message has been sent....!";
?>
我得到以下错误:
警告:mail(([function.mail]:无法连接到位于"smtp.gmail.com"端口465的邮件服务器,请验证php.ini中的"smtp"answers"smtp_port"设置,或在第31行上的C:''example''htdocs''testMail.php中使用ini_set((
致命错误:第33行的C:''examplep''htdocs''testMail.php中超过了30秒的最大执行时间
Gmail服务器使用TLS和登录/密码验证,您不能将它们与PHP的mail((函数一起使用。
尝试使用类似Swiftmailer的邮件库。下面是一个可以使用Gmail的示例:http://swiftmailer.org/wikidocs/v3/connections/smtp
您需要对gmail的SMTP服务器使用SMTP授权才能工作,而这在邮件中是无法做到的。
看看PHPMailer,他们在这里有一个很好的例子。
有时isp在某种程度上为其客户端提供免费的smtp服务。谷歌yourisp&smtp。