【发布时间】: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?