我正在创建一个联系我们表单,该表单应通过电子邮件将表格内容发送给我。我尝试在我的localhost上发送邮件,但它没有用,但在主机(1和1)上它可以正常工作。现在,我正在尝试新主机(Netfirms)。一些明显的原因,邮件功能不发送邮件,并且它不返回true / false值。我整夜都在谷歌搜索解决方案或理论,但这没用。什么可能导致这种奇怪的结果?
这是邮件的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>');
}
}
}
}
?>
答案 0 :(得分:2)
所以我很好奇这是如何在其他主机上工作的。在进入邮件功能之前,您将退出该功能。
你的两个转换语句:
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;
}
这些是返回的字符串,这意味着只要案例匹配,在switch语句之后就不会执行任何代码。
也许您正在尝试重新定义变量,如下所示:
switch($event_type) {
case '1':
$event_type = 'Baby Shower';
break;
case '2':
$event_type = 'Wedding';
break;
case '3':
$event_type = 'Kids Party';
break;
case '4':
$event_type = 'Birthday';
break;
case '5':
$event_type = 'Other';
break;
}
switch($guests) {
case '1':
$guests = '10-25 People';
break;
case '2':
$guests = '25 - 50 People';
break;
case '3':
$guests = '50 - 75 People';
break;
case '4':
$guests = '75 - 100+ People';
break;
}
答案 1 :(得分:0)
您是否检查过端口25是否已打开?这是一个链接: http://www.yougetsignal.com/tools/open-ports/