【问题标题】:SMTP setup in PHP for HTML form用于 HTML 表单的 PHP 中的 SMTP 设置
【发布时间】:2014-06-12 19:36:39
【问题描述】:

我有一个网站,我在网站上创建了一个联系表,但我的托管计划不包括 SMTP,所以我无法从我的联系表中获取消息,有什么方法可以在 PHP 表单中设置 SMTP ?如果是这样,这是我的 php,谢谢你的帮助。

<?php

    if(isset($_POST['email'])) {



// EDIT THE 2 LINES BELOW AS REQUIRED

$email_to = "nabelou10@gmail.com";

$email_subject = "Your email subject line";





function died($error) {

    // your error code can go here

    echo "We are very sorry, but there were error(s) found with the form you submitted. ";

    echo "These errors appear below.<br /><br />";

    echo $error."<br /><br />";

    echo "Please go back and fix these errors.<br /><br />";

    die();

}



// validation expected data exists

if(!isset($_POST['first_name']) ||

    !isset($_POST['last_name']) ||

    !isset($_POST['email']) ||

    !isset($_POST['telephone']) ||

    !isset($_POST['comments'])) {

    died('We are sorry, but there appears to be a problem with the form you submitted.');       

}



$first_name = $_POST['first_name']; // required

$last_name = $_POST['last_name']; // required

$email_from = $_POST['email']; // required

$telephone = $_POST['telephone']; // not required

$comments = $_POST['comments']; // required
// create email headers

    $headers = 'From: '.$email_from."\r\n".

    'Reply-To: '.$email_from."\r\n" .

    'X-Mailer: PHP/' . phpversion();

    @mail($email_to, $email_subject, $email_message, $headers);  

    ?>

【问题讨论】:

  • 您尝试过使用 SMTP 库吗?
  • @Ohgodwhy no 我不知道那是什么,谢谢你的回答
  • @Ohgod为什么支持 HTML?

标签: php html email smtp


【解决方案1】:

使用 phpmailer 来使用 smtp 。您可以设置您的 Gmail SMTP 凭据以测试电子邮件是否正常工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-17
    • 2022-01-07
    • 1970-01-01
    相关资源
    最近更新 更多