I have a classic LAMP platform (Debian, Apache2, PHP5 and MySQL) on a dedicated server.
我在专用服务器上有一个经典的LAMP平台(Debian,Apache2,PHP5和MySQL)。
I heard PHPMailer can send email without having installed SMTP. Is PHPMailer the best choice for this?
我听说PHPMailer可以在没有安装SMTP的情况下发送电子邮件。 PHPMailer是最好的选择吗?
3 个解决方案
#1
19
Yes, PHPMailer is a very good choice.
是的,PHPMailer是一个非常好的选择。
For example, if you want, you can use the googles free SMTP server (it's like sending from your gmail account.), or you can just skip the smtp part and send it as a typical mail() call, but with all the correct headers etc. It offers multipart e-mails, attachments.
例如,如果你愿意,你可以使用谷歌免费的SMTP服务器(就像从你的Gmail帐户发送。),或者你可以跳过smtp部分并将其作为典型的mail()调用发送,但所有正确的它等提供多部分电子邮件,附件。
Pretty easy to setup too.
设置也很容易。
<?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;
}
?>
#2
3
Without SMTP, you can use the PHP mail function: http://php.net/manual/en/function.mail.php
没有SMTP,您可以使用PHP邮件功能:http://php.net/manual/en/function.mail.php
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
#3
1
You can use phpmailer to send using the default php mail() function as well.
您也可以使用phpmailer使用默认的php mail()函数发送。
I recommend not trying to do things manually using the mail() function, use phpmailer instead and configure it to use mail().
我建议不要尝试使用mail()函数手动执行,而是使用phpmailer并将其配置为使用mail()。
I'd like to point out that even though you're not using an SMTP connection to send the mails yourself, the mail() function will use either an SMTP connection or the server's sendmail program to send out the emails anyways, so that will have to be configured for it to work correctly.
我想指出的是,即使你没有使用SMTP连接自己发送邮件,mail()函数也会使用SMTP连接或服务器的sendmail程序来发送电子邮件,这样就可以了必须配置它才能正常工作。
#1
19
Yes, PHPMailer is a very good choice.
是的,PHPMailer是一个非常好的选择。
For example, if you want, you can use the googles free SMTP server (it's like sending from your gmail account.), or you can just skip the smtp part and send it as a typical mail() call, but with all the correct headers etc. It offers multipart e-mails, attachments.
例如,如果你愿意,你可以使用谷歌免费的SMTP服务器(就像从你的Gmail帐户发送。),或者你可以跳过smtp部分并将其作为典型的mail()调用发送,但所有正确的它等提供多部分电子邮件,附件。
Pretty easy to setup too.
设置也很容易。
<?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;
}
?>
#2
3
Without SMTP, you can use the PHP mail function: http://php.net/manual/en/function.mail.php
没有SMTP,您可以使用PHP邮件功能:http://php.net/manual/en/function.mail.php
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
#3
1
You can use phpmailer to send using the default php mail() function as well.
您也可以使用phpmailer使用默认的php mail()函数发送。
I recommend not trying to do things manually using the mail() function, use phpmailer instead and configure it to use mail().
我建议不要尝试使用mail()函数手动执行,而是使用phpmailer并将其配置为使用mail()。
I'd like to point out that even though you're not using an SMTP connection to send the mails yourself, the mail() function will use either an SMTP connection or the server's sendmail program to send out the emails anyways, so that will have to be configured for it to work correctly.
我想指出的是,即使你没有使用SMTP连接自己发送邮件,mail()函数也会使用SMTP连接或服务器的sendmail程序来发送电子邮件,这样就可以了必须配置它才能正常工作。