I’m trying to code a script in order to mail the user upon his/her successful registration using PHP.
The user gets registered successful in the database, though the email is not being sent.
Here is my code:
<?php
function send_mail($id,$name,$email,$password)
{
$from='Admin <admin@mydomain.com>';
$headers = '';
$headers .= "From: $from\n";
$headers .= "Reply-to: $from\n";
$headers .= "Return-Path: $from\n";
$headers .= "Message-ID: <" . md5(uniqid(time())) . "@" . $_SERVER['SERVER_NAME'] . ">\n";
$headers .= "Date: " . date('r', time()) . "\n";
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
}
$subject = "Welcome!";
$message = "
<p></p><br>
Hi ".$name."<br>
Thank you for registering for the event.<br><br>
Your ID is ".$id."<br>
Login using your email id : ".$email." and,<br>
your password : ".$password."<br><br>
";
mail($email,$subject,$message,$headers);
?>
In my register.php script I’ve included:
send_mail($u_id,$u_name,$_POST['email'],$password)
The parameters of the function are id (INT), name (VARCHAR), email (VARCHAR) & password (VARCHAR)
I think your mail() function is outside of send_mail() function.
Change it into,