我有一张要求提供电子邮件地址的表单。如果客户没有电子邮件字段中的电子邮件地址示例:电子邮件字段中的George而不是george@aol.com我仍然希望它发送表单。 我假设它是phpmailer本身,我不知道如何解决它。
是否可以更改class.phpmailer.php中的设置?
<?php
//values to be inserted in database table
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$phone = $_POST['phone'] ;
$make = $_POST['make'] ;
$model = $_POST['model'] ;
$year = $_POST['year'] ;
$vin = $_POST['vin'] ;
$insurance_company = $_POST['insurance_company'] ;
$name = $_POST['name'] ;
$message = $_POST['message'] ;
$IP = $_SERVER['REMOTE_HOST'] ?: gethostbyaddr($_SERVER['REMOTE_ADDR']);
if (isset($_POST['submit'])){
//cleans the data
$_POST = preg_replace("/[^-,A-Za-z0-9,@,')','(','.' ]/", "",$_POST);
//connect to db
$db = new mysqli('localhost','user','pass','database');
//MySqli Insert Query
$insert_row = $db->query("INSERT INTO `data`(`name`, `email`, `phone`, `IP`) VALUES ('$name','$email','$phone','$IP')");
$token = $_SESSION['delete_customer_token'];
unset($_SESSION['delete_customer_token']);
session_write_close();
//check if post form was submitted
if(isset($_POST)){
//check if hidden value was used
if(isset($_POST['miles']) && trim($_POST['miles']) !=''){
die('THERE WAS AN ERROR');
}
//implode all the post data and check against bad words in a text file
$my_bad_file = "inc/words.txt"; //make a new file and insert any bad items one per line, Phrases work as well
if(!file_exists($my_bad_file)){
die("Can't find $my_bad_file");
}
$check_content = implode(",", $_POST);
$bad_content_array = array_map('rtrim', file($my_bad_file));
foreach ($bad_content_array as $bad_content) {
$bad_content = strtolower($bad_content);
if (strpos(strtolower($check_content), $bad_content) !== false) {
die('THERE WAS A BAD ERROR');
}}
}
require 'inc/PHPMailer/PHPMailerAutoload.php';
// PHPmailer settings
$mail = new PHPMailer(); // create a new object
$mail->Issmtp(); // enable SMTP
$mail->SMTPDebug = true;
$mail->do_debug = 1;
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = "info@website.com"; // SMTP username
$mail->Password = "password"; // SMTP password
$mail->FromName = $email;
$mail->SetFrom($email);
$mail->AddAddress('info@website.com');
$mail->Priority = 1;
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "company name | Repair Quote";
$mail->AltBody = "This is the text-only body";
// defines how message looks in email
$mail->Body="
<html>
<head>
</head>
<body>
<center>
<span style='color:red;'>This customer needs a repair quote. Lets not keep him waiting!</span>
<div style='width:750px;text-align:center;'>
<div style='float:;'>
<span style='font-size:px;'><b>Personal Info</b><br></span>
<br>
<span style='font-size:px;'>---------------<br></span>
<br>
<span style='font-size:px;'><span style='font-size:px;color:red;'>Full Name: </span>$name<br></span>
<br>
<span style='font-size:px;'><span style='font-size:px;color:red;'>Phone Number:</span> $phone<br></span>
<br>
<span style='font-size:px;'><span style='font-size:px;color:red;'>Email:</span> $email<br></span>
</div>
<br>
<div style='float:;'>
<span style='font-size:px;'><b>Vehicle Info</b><br></span>
<br>
<span style='font-size:px;'>---------------<br></span>
<br>
<span style='font-size:px;'><span style='font-size:px;color:red;'>Vehicle make:</span> $make<br></span>
<br>
<span style='font-size:px;'><span style='font-size:px;color:red;'>Vehicle Model:</span> $model<br></span>
<br>
<span style='font-size:px;'><span style='font-size:px;color:red;'>Year:</span> $year<br></span>
<br>
<span style='font-size:px;'><span style='font-size:px;color:red;'>Vin:</span> $vin<br></span>
<br>
<span style='font-size:px;'><span style='font-size:px;color:red;'>Insurance Company:</span> $insurance_company<br></span>
<br>
<span style='font-size:px;'><span style='font-size:px;color:red;'>Message:</span>$message<br></span>
</div>
</div>
</center>
</body>
</html>
";
// looks good in your inbox
$mail->From = "$email";
$mail->FromName = "$name";
$mail->AddReplyTo("$email","$name");
$mail->SetFrom('$email', '$name');
// gives success or error
if(!$mail->Send()) {
echo 'Message could not be sent.';
exit;
} else{
echo '
<meta http-equiv="refresh" content="0;url=http://website.com/index.php">
';}
}
?>
&#13;
答案 0 :(得分:0)
你有一个基本的编程方法 - 你只是假设事情会起作用而不是检查返回值。如果您在setFrom
的调用中尝试使用无效地址,则会返回false,对于addAddress
等所有其他地址设置功能也是如此。
不要将提交者的地址放在发件人地址中 - 它将无法通过SPF检查。将他们的地址放在回复地址中,并将您的地址作为发件人地址。
您已将您的代码基于一个过时的示例 - 请确保您使用the latest version并使用the examples provided wtih it。
答案 1 :(得分:0)
我认为您可以将来自电子邮件和回复电子邮件的内容更改为info@website.com,而不是用户输入的电子邮件。然后你知道它总是一封有效的电子邮件。我不确定您的SMTP是否允许从无效的电子邮件发送。
缺点是您无法直接回复用户,但必须从邮件正文中复制电子邮件地址。也许你可以将电子邮件地址设置为正文中的mailto:链接?