首页 文章

如何从联系表单发送和接收电子邮件 - mail()vs phpmailer [duplicate]

提问于
浏览
-2

这个问题在这里已有答案:

出于学习目的,我想知道如何为我的网站制作联系表格 .

我不明白 . 我交谈的每个人都建议我不要在PHP中使用mail()函数,因为它有很多问题,邮件转到垃圾邮件或者甚至不发送,但是我在网上看到的每个教程正在使用mail()函数 .

我甚至从网上下载了一份完整的联系表格,他们正在使用mail() .

我甚至下载了具有所有功能的完整网站模板和在线商店模板,他们甚至使用mail()函数 .

所以我也听说过phpMailer或swiftMailer,我在OOP的知识不是很强,但我下载了一些教程,而且我意识到这个phpMailer的想法是从我的电子邮件发送电子邮件给其他人 .

我想接收客户(从联系方式)到我的电子邮件的电子邮件 . 最好的方法是什么?我可以使用任何代码片段来为我的项目学习吗?

1 回答

  • 0

    基本上在下载phpMailer之后,只需测试以下代码并根据自己的喜好进行调整 .

    include 'class.phpmailer.php';
    
    // Sendmail
    $arr_mail = array(
        "email"             => "user_email@domain.tld", // user email
        "name"              => "user name",
        "system_email"      => "mail@domain.tld", // your email
        "system_from_name"  => "Your Name", // your name
        "subject"           => "Subject", 
        "message"           => "The Message",
        "message_template"  => "/path/template.html.php",
        "attachment"        => "/path/to/attachment"
    );
    $sendmail->sendMail($arr_mail);
    

    另外phpMailer类有很多样本,你可以尝试每一个,找到更适合你的东西 .

相关问题