从PHP发送HTML电子邮件
MYSqL工作正常,但我没有收到电子邮件为什么从PHP发送HTML电子邮件,php,forms,email,sendmail,html-email,Php,Forms,Email,Sendmail,Html Email,MYSqL工作正常,但我没有收到电子邮件为什么 <?php //include the connection file require_once('connection.php'); //save the data on the DB and send the email if(isset($_POST['action']) && $_POST['action'] == 'submitform') {
<?php
//include the connection file
require_once('connection.php');
//save the data on the DB and send the email
if(isset($_POST['action']) && $_POST['action'] == 'submitform')
{
//recieve the variables
$name = $_POST['name'];
$email = $_POST['email'];
$url = $_POST['url'];
$comment = $_POST['comment'];
$ip = gethostbyname($_SERVER['REMOTE_ADDR']);
//save the data on the DB
mysql_select_db($database_connection, $connection);
$insert_query = sprintf("INSERT INTO contacts (name, email, url, comment, date, ip) VALUES (%s, %s, %s, %s, NOW(), %s)",
sanitize($name, "text"),
sanitize($email, "text"),
sanitize($url, "text"),
sanitize($comment, "text"),
sanitize($ip, "text"));
$result = mysql_query($insert_query, $connection) or die(mysql_error());
if($result)
{
//send the email
$to = "email@aol.com";
$subject = "message from website";
//headers and subject
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: ".$name." <".$email.">\r\n";
$body = "New contact<br />";
$body .= "Name: ".$name."<br />";
$body .= "Email: ".$email."<br />";
$body .= "Comment: ".$comment."<br />";
$body .= "IP: ".$ip."<br />";
mail($to, $subject, $body, $headers);
//ok message
echo "Your message has been sent";
}
}
function sanitize($value, $type)
{
$value = (!get_magic_quotes_gpc()) ? addslashes($value) : $value;
switch ($type) {
case "text":
$value = ($value != "") ? "'" . $value . "'" : "NULL";
break;
case "long":
case "int":
$value = ($value != "") ? intval($value) : "NULL";
break;
case "double":
$value = ($value != "") ? "'" . doubleval($value) . "'" : "NULL";
break;
case "date":
$value = ($value != "") ? "'" . $value . "'" : "NULL";
break;
}
return $value;
}
?>
当电子邮件突然停止时,从服务器发送电子邮件可能很棘手。您肯定希望在发生故障时实现某种类型的日志记录。关于你的特殊问题,这可能是一系列的事情
MySQL
与mail()
无关,因此一种工作方式对另一种工作方式没有直接影响,除非您有指定这种交互的代码。这是一个相当技术性的解释
aol.com
。如果是这样的话,那么你会想看看这个。他们可能正在执行一个任务,但在反向查找中找不到您的服务器名称。此外,他们喜欢,和$\u服务器['SERVER\u ADDR']
是否在阻止列表中。例如,您可以尝试:mail()
事务的日志来更新配置文件。这将告诉您电子邮件是否被退回,以及服务器之间握手期间是否有任何响应我们可以使用您的代码中创建$to、$subject、$headers变量的部分吗?您是否在本地服务器上运行此程序?如果是,则需要在其上配置邮件(即sendmail)服务器。您需要在问题中发布相关代码。否则,我们无能为力/哇,你打字很快,或者有很多空闲时间:-)解释得很好。。谢谢@AbsoluteZero