我尝试使用SMTP服务器发送邮件,并且进行了所有配置。我收到消息说发送了电子邮件,谢谢。但是当我进入我的电子邮件帐户时,没有邮件。另外,由于我试图将电子邮件从我的邮件地址发送到另一个地址,因此我收到一封邮件,提示有人试图登录您的帐户。我在这里了解到的是,该代码可以登录我的帐户,但无法发送邮件。这可能是什么问题?
这是我在sendmail.ini文件中所做的:
**
**
这是我的代码:
<?php
ini_set("SMTP","ssl://smtp.gmail.com");
ini_set("smtp_port","465");
if(isset($_POST['submit'])){
$to = "mygmailadres@gmail.com"; // this is my Email address
$from = $_POST['email']; // this is the user's Email address
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$subject = "Form submission";
$subject2 = "Copy of your form submission";
$message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['message'];
$message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
}
?>
<!DOCTYPE html><head><title>Form submission</title></head><body>
<form action="" method="post">
First Name: <input type="text" name="first_name"><br>
Last Name: <input type="text" name="last_name"><br>
Email: <input type="text" name="email"><br>
Message:<br><textarea rows="5" name="message" cols="30"></textarea><br>
<input type="submit" name="submit" value="Submit">
</form></body>
</html>
答案 0 :(得分:0)
要使其正常运行,需要在GMAIL中进行几个设置。请检查以下几点。
当我尝试上述所有步骤时,它对我有用。如果它们都不起作用,那么您需要检查错误日志文件以确定其停止发送电子邮件的确切原因。