HTML表单的PHP SMTP设置


SMTP setup in PHP for HTML form

我有一个网站,我在网站上创建了一个联系人表单,但我的托管计划不包括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);  
    ?>

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