Reputation: 81
my php mail() function is not working even its right here it is
$to = $email_id;
$sub = "FORGOT PASSWORD";
$msg = $password;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'From: Your name <[email protected]>' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$mail= mail($to,$sub,$msg,$headers);
if($mail)
{
?>
<script>alert('Your password has been successfully sent to you');</script>
<?
}
else
{
?>
<script>alert('Please try again later');</script>
<?
}
its alert if part i.e. Your password has been successfully sent to you but i did not received any email please help me and i am not using any HTML css in sending this mail.
Upvotes: 2
Views: 241
Reputation: 487
your headers are incorrect use your headers in this way it will resolved your problem getting true part is not a big deal
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'From: Your name <example@you_domain_name.com>' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
if not resolved give me the result you get using var_dump($mail); showing bool(true)
Upvotes: 1
Reputation: 5166
no need to use "" in the mail function if you are storing it in a variable allready.
second thing check what you are getting in $email_id;
variable is it the correct email address you are trying to send email .
simply use like this
<?php
$to = $email_id;
$sub = "FORGOT PASSWORD";
$msg = $password;
$headers = "From: [email protected]" . "\r\n" .
"CC: [email protected]";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$mail=mail($to,$sub,$msg ,$headers);
if($mail)
{
?>
<script>alert('Your password has been successfully sent to you');</script>
<?
}
else
{
?>
<script>alert('Please try again later');</script>
<?
}
?>
Update
also please check your spam folder. as if you are using other domain as from email
these emails may go to the spam folder . or you can use these headers
$headers = "From: [email protected]" . "\r\n" .
"CC: [email protected]"; // enter your domain email
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
Upvotes: 0
Reputation: 434
Write your domain name
$headers .= 'From: Your name <example@yorudomainname>' . "\r\n";
example <[email protected]/>
Upvotes: 0
Reputation: 41
Use this mail($to, $sub, $msg, $headers),
If it returns true, then check your spam folder.
Upvotes: 0
Reputation: 11693
use
$mail= mail($to, $sub, $msg, $headers);
You dont need string as all variables are Already string.
Upvotes: 1