PHP脚本不会向我的帐户发送电子邮件

时间:2013-11-17 08:56:39

标签: php html forms email

任何人都可以帮我解决这个PHP代码。我在我的联系我们页面中使用php代码向我的帐户发送电子邮件。不知何故,代码无效。此代码的基本功能是捕获用户输入的详细信息并将详细信息发送到我的电子邮件帐户。但不知何故,PHP代码正在执行,并没有显示任何错误,但没有向我的帐户发送电子邮件。那么,有人请建议我哪里出错了...谢谢大家...

以下是我正在使用的PHP代码:

<?php
error_reporting(0);
error_reporting (E_NONE);

$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$mob_no = $_POST['mob_no'];
$email = $_POST['email'];
$course = $_POST['course'];
$location = $_POST['location'];
$city = $_POST['city'];
$to = "example@mywebsite.com";
$subject = 'Request Assistance';

$headers = array();
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset = iso-8859-1';
$headers[] = 'Content-Transfer-Encoding: 7bit';
$headers[] = 'From: ' . $first_name . " " . $last_name;

$message .= "First Name: " . $first_name . "\n";
$message .= "Last Name: " . $last_name . "\n";
$message .= "Mobile No: " . $mob_no . "\n";
$message .= "E-Mail: " . $email . "\n";
$message .= "Course: " . $course . "\n";
$message .= "Location: " . $location . "\n";
$message .= "City: " . $city . "\n";
?>



<?php
$success = mail($to, $subject, $message, $headers);

if (($_POST['first_name'] == "") || ($_POST['last_name'] == "") || ($_POST['mob_no'] ==      "") || ($_POST['email'] == "") || ($_POST['course'] == "") || ($_POST['location'] == "") ||($_POST['city'] == "")) {
echo '<h1>Sorry for the inconvenience!</h1>';
echo '<p>We have encountered a problem, Please Note:<br />';
echo 'Make sure you fill in all the details<br />';
echo 'Do not use spaces or special characters, except in E-Mail.<br />';
echo 'Inconvenience is deeply regretted!!!</p>';
}

if ((!ctype_alpha($first_name)) || (!ctype_alpha($last_name)) || (!ctype_digit($mob_no)) || (!ctype_alpha($course)) || (!ctype_alpha($location)) || (!ctype_alpha($city))) {
echo '<h1>Sorry for the inconvenience!</h1>';
echo '<p>We have encountered a problem, Please Note:<br />';
echo 'Make sure you fill in all the details<br />';
echo 'Do not use spaces or special characters, except in E-Mail.<br />';
echo 'Inconvenience is deeply regretted!!!</p>';
}

if ($success) {
echo '<h1>Congratulations!</h1>';
echo '<p>The following message has been sent:<br /><br />';
echo '<b>To:</b> ' . $to . '<br />';
echo '<b>From:</b> ' . $email . '<br />';
echo $message;
}
?>

1 个答案:

答案 0 :(得分:0)

您的代码本身对我来说没有错,请参阅以下内容: 1.确保主机启用邮件功能 2.使用邮件可能会导致垃圾文件夹有时会有多少垃圾邮件使用它 3.尝试使用phpmailer,类似于邮件,但更可配置