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


The PHP script is not sending emails to my account

任何人都可以帮我处理这个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. 确保您的主机启用邮件功能2.使用邮件有时可能会导致垃圾邮件文件夹,因为许多垃圾邮件都使用它3. 尝试使用 phpmailer,类似于邮件,但可配置性更强

相关文章: