Index.html
<html>
<head>
</head>
<body>
<form method="post" action="send_mail.php">
Name : <input type="text" name="name">
To : <input type="text" name="email"> <br/>
<br/>
<input type="submit" value="Send Email">
</form>
</body>
</html>
Index has 2 fields, name and Email.
send_mail.php
<?php
$conn = mysqli_connect("localhost", "root", "" ,"db") or die("Error Connection");
$name = $_POST['name'];
$mail = $_POST['email'];
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$pass = substr( str_shuffle( $chars ), 0, 8 );
require 'PHPMailer-master/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail ->IsSmtp();
$mail ->SMTPDebug = 0;
$mail ->SMTPAuth = true;
$mail ->SMTPSecure = 'ssl';
$mail ->Host = "smtp.gmail.com";
$mail ->Port = 465; // or 587
$mail ->IsHTML(true);
$mail ->Username = "*********@gmail.com";
$mail ->Password = "********";
$mail ->SetFrom("********@gmail.com");
$mail ->Subject = "Here goes Subject";
$mail ->Body = "Password is ".$pass;
$mail ->AddAddress('$mail');
if(!$mail->Send())
{
echo "Mail Not Sent";
}
else
{
echo "Mail Sent";
}
I want to send random generated password to email which is being registered above. I'm using PHPMailer. Output: Mail not sent. I can't figure out the error. If anyone can please do me this favor.
Aucun commentaire:
Enregistrer un commentaire