我正在创建一个联系我们的表格,它应该通过电子邮件将表格的内容发送给我。我试图在我的本地主机上发送邮件,但它没有工作,但在主机(1and1)上它工作得很好。现在,我正在新主机(Netfirms)上试用它。出于某种明显的原因,邮件函数不发送邮件,也不返回真/假值。我整晚都在谷歌上搜索解决方案或理论,但没有用。什么可能导致这种奇怪的结果?
这是邮件的PHP。
<?php
class zMail {
final public function compileMail() {
global $tpl, $zip;
$tpl->Define('error', null);
# Ensure that the form was sent #
if(isset($_POST['contact-us'])) {
# Make sure that the variables are set for the mailing process #
$first_name = $_POST['f_name'];
$last_name = $_POST['l_name'];
$event_type = $_POST['event'];
$date = $_POST['date'];
$guests = $_POST['guests'];
$from = $_POST['email'];
$phone = $_POST['phone'];
# Place Where E-Mail should be sent to #
$to = $zip['Social']['Email'];
# Are all fields completed? #
if(!empty($first_name) && !empty($last_name) && !empty($event_type) && !empty($date) && !empty($guests) && !empty($from) && !empty($phone)) {
switch($event_type) {
case '1':
return 'Baby Shower';
break;
case '2':
return 'Wedding';
break;
case '3':
return 'Kids Party';
break;
case '4':
return 'Birthday';
break;
case '5':
return 'Other';
break;
}
switch($guests) {
case '1':
return '10-25 People';
break;
case '2':
return '25 - 50 People';
break;
case '3':
return '50 - 75 People';
break;
case '4':
return '75 - 100+ People';
break;
}
$message = '<ul>
<li><b>First & Last Name: </b><span style="float: right;">' . $first_name . ' ' . $last_name . '</span></li>
<li><b>Event Type: </b><span style="float: right;">' . $event_type . '</span></li>
<li><b>Date: </b><span style="float: right;">' . $date . '</span></li>
<li><b>Guests: </b><span style="float: right;">' . $guests . '</span></li>
<li><b>Email: </b><span style="float: right;">' . $from . '</span></li>
<li><b>Telephone: </b><span style="float: right;">' . $phone . '</span></li>
<li><b>Add`l Information: </b><span style="float: right;">' . $notes . '</span></li>
</ul>';
$subject = "{site: title} - New Client Inquiry";
$headers = "From: IntactDev@gmail.com\r\n" .
'X-Mailer: PHP/' . phpversion() . "\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: text/html; charset=utf-8\r\n" .
"Content-Transfer-Encoding: 8bit\r\n\r\n";
$retval = mail($to, $subject, $message, $headers);
if($retval == true) {
$tpl->Define('error', '<span class="error">Message sent successfully!</span>');
} else {
$tpl->Define('error', '<span class="error">Email could not be sent!</span>');
}
} else {
$tpl->Define('error', '<span class="error">Please fill in all fields!</span>');
}
}
}
}
?>