Mic*_*all 9 php email mime phpmailer
我正在尝试发送一个Plain/HTML多部分电子邮件,我目前正在使用PHP的mail()函数.很多人推荐PHPMailer所以我想我会试一试.
然而,就像现在似乎所有事情一样,它看起来非常复杂.我下载了它,它讨论了安装它并配置MySQL连接和SMTP连接!?我想要做的就是使用一个很好的类来为我构建MIME电子邮件并发送它们!我理解SMTP的可能性但它看起来都很复杂!
有没有办法简单地使用它,例如,包括一个PHP文件(没有服务器安装或重新编译PHP!)然后只是使用该类来构建和发送电子邮件?
如果有人能够简单地解释一下,我将非常感激!我确信这是可能的,我不能相信,经过几个小时的搜索,在网上没有关于它的真正好的,简单的文章.当我知道它不需要时,一切都太复杂了!
漂亮的方式(从这个链接),首先扩展PHPMailer并设置您的网站的默认值:
require("class.phpmailer.php");
class my_phpmailer extends phpmailer {
// Set default variables for all new objects
var $From = "from@example.com";
var $FromName = "Mailer";
var $Host = "smtp1.example.com;smtp2.example.com";
var $Mailer = "smtp"; // Alternative to IsSMTP()
var $WordWrap = 75;
// Replace the default error_handler
function error_handler($msg) {
print("My Site Error");
print("Description:");
printf("%s", $msg);
exit;
}
// Create an additional function
function do_something($something) {
// Place your new code here
}
}
Run Code Online (Sandbox Code Playgroud)
然后在需要的地方包含上面的脚本(在此示例中将其命名mail.inc.php)并my_phpmailer在您的站点上的某处使用新创建的类:
require("mail.inc.php");//or the name of the first script
// Instantiate your new class
$mail = new my_phpmailer;
// Now you only need to add the necessary stuff
$mail->AddAddress("josh@example.com", "Josh Adams");
$mail->Subject = "Here is the subject";
$mail->Body = "This is the message body";
$mail->AddAttachment("c:/temp/11-10-00.zip", "new_name.zip"); // optional name
if(!$mail->Send())
{
echo "There was an error sending the message";
exit;
}
echo "Message was sent successfully";
Run Code Online (Sandbox Code Playgroud)