我在一台专用服务器上有一个经典的LAMP平台(Debian、Apache2、PHP5和MySQL)。
我听说PHPMailer可以在没有安装SMTP的情况下发送邮件。PHPMailer是不是最好的选择呢?
发布于 2011-02-11 07:07:51
是的,PHPMailer是一个非常好的选择。
例如,如果你愿意,你可以使用googles免费的SMTP服务器(就像从你的gmail帐户发送一样),或者你可以跳过smtp部分,作为一个典型的mail()调用发送它,但带有所有正确的头部等。
设置起来也很容易。
<?php
$mail = new PHPMailer(true);
//Send mail using gmail
if($send_using_gmail){
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "your-gmail-account@gmail.com"; // GMAIL username
$mail->Password = "your-gmail-password"; // GMAIL password
}
//Typical mail data
$mail->AddAddress($email, $name);
$mail->SetFrom($email_from, $name_from);
$mail->Subject = "My Subject";
$mail->Body = "Mail contents";
try{
$mail->Send();
echo "Success!";
} catch(Exception $e){
//Something went bad
echo "Fail - " . $mail->ErrorInfo;
}
?>
发布于 2011-02-11 07:05:56
您也可以使用phpmailer使用默认的php mail()函数进行发送。
我建议不要尝试使用mail()函数手动执行操作,而是使用phpmailer并将其配置为使用mail()。
我想指出的是,即使您没有使用SMTP连接自己发送邮件,mail()函数也会使用SMTP连接或服务器的sendmail程序发送电子邮件,因此必须对其进行配置才能正常工作。
发布于 2011-02-11 07:01:52
如果没有SMTP,您可以使用PHP mail函数:http://php.net/manual/en/function.mail.php
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
https://stackoverflow.com/questions/4963688
复制相似问题