我试图从我的localhost发送邮件,但它不起作用。我更改了SMTP上的设置,但它仍然没有发送。
这是我的html代码
<html>
<head>
<title>Subscribe</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<li><a href="admin.php">Admin</a></li>
<li> <a href="index.php">Home<a></li>
<form action="email.php" method="post">
name : <input action="email.php" class="name" type="text" name="username">
<br>
email : <input class="email" type="text" name="email">
<br>
<input name="submit" type="submit" value="insert">
</form>
</body>
</html>
这是我的php代码
<?php
$con = mysqli_connect('127.0.0.1', 'root', '');
if(!$con) {
echo "not connected to server";
}
if(!mysqli_select_db($con, "task")) {
echo "database not conncted";
}
$Name=$_POST["username"];
$Email=$_POST["email"];
$sql = "insert into person (Name,Email) VALUES ('$Name','$Email')";
if(!mysqli_query($con, $sql)) {
echo "error!!!!!";
}
$msg = <<<EMAIL
Hello $Name
Thank you!! You Have Subscribe To Us.
EMAIL;
$subject = "Welcome Massage";
if ($_POST['submit']) {
$success = mail($Email, $subject, $msg);
if($success)
{
echo '
<p>Your message has been sent!</p>
';
} else {
echo '
<p>Something went wrong, go back and try again!</p>
';
}
}
header ("refresh:2; url=index.php");
?>
这是我为php.ini更改的内容
SMTP = smtp.gmail.com
smtp_port = 465
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = xxxxxxx@gmail.com
; XAMPP IMPORTANT NOTE (1): If XAMPP is installed in a base directory with spaces (e.g. c:\program filesC:\xampp) fakemail and mailtodisk do not work correctly.
; XAMPP IMPORTANT NOTE (2): In this case please copy the sendmail or mailtodisk folder in your root folder (e.g. C:\sendmail) and use this for sendmail_path.
; XAMPP: Comment out this if you want to work with fakemail for forwarding to your mailbox (sendmail.exe in the sendmail folder)
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
; XAMPP: Comment out this if you want to work with mailToDisk, It writes all mails in the C:\xampp\mailoutput folder
; sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe"
这是我在sendmail.ini中更改的内容
smtp_server=smtp.gmail.com
; smtp port (normally 25)
smtp_port=465
smtp_ssl=SSL
auth_username=myEmail@gmail.com
auth_password=myPass
它仍然无法正常工作。请帮忙