以下是基本电子邮件function.script的代码。它实际上使用网站上的表单来设置上面脚本中的变量以发送电子邮件。但它不能很好地工作,请帮我解决它!
<?php
//if "email" variable is filled out, send email
if (isset($_REQUEST['email'])) {
//Email information
$admin_email = "someone@example.com";
$email = $_REQUEST['email'];
$subject = $_REQUEST['subject'];
$comment = $_REQUEST['comment'];
//send email
mail($admin_email, "$subject", $comment, "From:" . $email);
//Email response
echo "Thank you for contacting us!";
}
//if "email" variable is not filled out, display the form
else {
?>
<form method="post">
Email: <input name="email" type="text" /><br />
Subject: <input name="subject" type="text" /><br />
Message:<br />
<textarea name="comment" rows="15" cols="40"></textarea><br />
<input type="submit" value="Submit" />
</form>
<?php
}
?>
答案 0 :(得分:3)
试试这个 - 在代码中添加标题。
//if "email" variable is filled out, send email
if (isset($_REQUEST['email'])) {
//Email information
$admin_email = "someone@example.com";
$email = $_REQUEST['email'];
$subject = $_REQUEST['subject'];
$comment = trim($_REQUEST['comment']);
$headers = 'From:' .$email. "\r\n" .
'Reply-To: info@domain.com' . "\r\n" .
'MIME-Version: 1.0' . "\r\n" .
'Content-type: text/html; charset=iso- 8859-1' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
//send email
$result = mail($admin_email, $subject, $comment, $headers);
//Email response
if($result)
echo "Thank you for contacting us!";
else
echo "Something went wrong.";
}
答案 1 :(得分:0)
试试这个
mail($admin_email, $subject, $comment, "From:" . $email);
答案 2 :(得分:0)
您正在运行哪个服务器/环境?
如果是Linux / Ubuntu。可能是因为缺少了库。尝试使用以下命令安装它。
apt-get install sendmail
但是一些日志/输出会很好。程序是否会抛出任何错误/异常?
答案 3 :(得分:0)
试试这样:
//发送电子邮件
mail($admin_email, $subject, $comment, "From:" . $email);
如果不再发送邮件,那么您必须逐步调试代码并检查变量中是否存在所有值。