我已经制作了一封HTML电子邮件,到目前为止一切顺利。我打算用PHP发送它(使用mail();函数)。但是,当我这样做时,邮件没有到达hotmail和gmail帐户。我google了一下,人们建议使用PHPmailer。
我下载了PHPmailer并将其安装在我的服务器上。到现在为止还挺好。但现在我有以下代码:
<?php
set_include_path('.:c:\domains\mydomain\wwwroot\phpmailer\phpmailer.inc.php');
set_include_path('.:c:\domains\mydomain\wwwroot\phpmailer\smtp.inc.php');
require("phpmailer.inc.php");
$mail = new PHPMailer();
$mail->IsHTML(true);
$mail->From = "from@example.com";
$mail->AddAddress("mymail@mydomain.com");
$mail->Subject = "An HTML Message";
$mail->Body = "Hello, <b>my friend</b>! \n\n This message uses HTML entities!";
if($mail->Send()) {
echo 'Message is sent';
} else {
echo 'Message was not sent..';
echo 'Mailer error: ' . $mail->ErrorInfo;
}
?>
我遇到了几个问题:
另外,我看到有一个SMTP功能。如何使用这个功能?我需要写下自己的SMTP吗?
如果有人可以帮助我,我会很高兴的!
编辑:
class SMTP {
var $SMTP_PORT = 25; # the default SMTP PORT
var $CRLF = "\r\n"; # CRLF pair
var $smtp_conn; # the socket to the server
var $error; # error if any on the last call
var $helo_rply; # the reply the server sent to us for HELO
var $do_debug; # the level of debug to perform
/*
* SMTP()
*
* Initialize the class so that the data is in a known state.
*/
function SMTP() {
$this->smtp_conn = 0;
$this->error = null;
$this->helo_rply = null;
$this->do_debug = 0;
}
答案 0 :(得分:0)
我在不同的项目中使用PHPMailer。
我建议您通过SMTP发送邮件,当然PHPMailer支持它:
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host = "smtp.gmail.com" //(or the smtp server you use)
$mail->Port = "465" //(gmail uses secure smtp so that runs on port 465)
$mail->SMTPAuth = "true" //we need to autenticate to the server
$mail->SMTPSecure = "ssl" //we use ssl to protected the flow of info
$mail->Username = "mymail@gmail.com" //account
$mail->Password = "password" //password
//build the message
$mail->IsHTML(true);
$mail->From = "mymail@gmail.com";
$mail->AddAddress("mymail@mydomain.com"); //who receives the mail
$mail->Subject = "An HTML Message";
$mail->Body = "Hello, <b>my friend</b>! \n\n This message uses HTML entities!";
if($mail->Send()) {
echo 'Message is sent';
}
else {
echo 'Message was not sent..';
echo 'Mailer error: ' . $mail->ErrorInfo;
}