尝试创建联系表单的自动回复电子邮件时,我遇到一些问题。直到我尝试插入带有URL的部件,下面的代码才能正常工作。由于某些原因,当我尝试在邮件上添加url链接时,两封电子邮件均未发送。.您能帮我吗?非常感谢您:(每个url在代码中张贴的人,当然应该是一个不同的url)
$siteOwnersEmail = 'myemail@domain.com';
$bitter = 'http://example.com/';
$logo = 'http://example.com/img/logo.png';
$dshop = 'https://example.org';
$wchange = 'https://example.net';
$sdrink = 'http://example.com/';
$mclark = 'https://example.com';
if($_POST) {
$name = trim(stripslashes($_POST['contactName']));
$email = trim(stripslashes($_POST['contactEmail']));
$subject = trim(stripslashes($_POST['contactSubject']));
$contact_message = trim(stripslashes($_POST['contactMessage']));
// Check Name
if (strlen($name) < 2) {
$error['name'] = "Please enter your name.";
}
// Check Email
if (!preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email)) {
$error['email'] = "Please enter a valid email address.";
}
// Check Message
if (strlen($contact_message) < 15) {
$error['message'] = "Please enter your message. It should have at least 15 characters.";
}
// Subject
if ($subject == '') { $subject = "Contact Form Submission"; }
// Set Message
$message .= "Email from: " . $name . "<br />";
$message .= "Email address: " . $email . "<br />";
$message .= "Message: <br />";
$message .= $contact_message;
$message .= "<br /> ----- <br /> This email was sent from your site's contact form. <br />";
$message2 = 'Hi!,<br /><br />Thanks for contacting us.<br /><br />
We will respond to your query as soon as possible.<br /><br /><br /><br />
In the meantime you can find our product available online at <a href="'.$dshop.'"></a>' . $dshop . '
or <a href="'.$wchange.'"></a>' . $wchange . '
, Speciality Drinks (<a href="'.$sdrink.'"></a>' . $sdrink . ')
and Matthew Clark (<a href="'.$mclark.'"></a>' . $mclark . ')
all providing worldwide delivery services.<br /><br />
From UK and EU you can also order it through this account for the price of £15 per bottle plus delivery,
via sending details of quanties needed and a delivery address
at main@domain.com<br /><br /><br />Kind regards,<br /><br />
our team<br /><br /><br />
<a href="'.$bitter.'"></a>' . $bitter . '<br />
<a href="'.$bitter.'"><img src="'.$logo.'" style="width:50px;"></a>';
$subject2 = "Thank you for your message";
// Set From: header
$from = $name . " <" . $email . ">";
// Email Headers
$headers = "From: " . $from . "\r\n";
$headers .= "Reply-To: ". $email . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers2 = "From: $siteOwnersEmail\r\n";
$headers2 .= "Content-type: text/html\r\n";
if (!$error) {
ini_set("sendmail_from", $siteOwnersEmail); // for windows server
$mail = mail($siteOwnersEmail, $subject, $message, $headers);
$mail = mail($email, $subject2, $message2, $headers2);
if ($mail) { echo "OK"; }
else { echo "Something went wrong. Please try again."; }
} # end if - no validation error
else {
$response = (isset($error['name'])) ? $error['name'] . "<br /> \n" : null;
$response .= (isset($error['email'])) ? $error['email'] . "<br /> \n" : null;
$response .= (isset($error['message'])) ? $error['message'] . "<br />" : null;
echo $response;
} # end if - there was a validation error
}