I am using wordpress mail and it returning me false.
pleas help me to checkout what's wrong in code.
$headers .= 'Content-Type: text/html; charset=ISO-8859-1' . "\r\n";
$headers .= 'From: abc#gmail.com';
$to ='user#gmail.com';
$mail_resp = wp_mail( $to , 'The subject', 'The message',$headers );
if($mail_resp){
echo "Mail send Sucessfully";
}
else{
echo "Mail Not send";
}
i am getting response mail not send Please help me to out of this what's wrong in this.
Thanks in advance
Try this one
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-Type: text/html; charset=ISO-8859-1' . "\r\n";
$headers .= 'From: abc#gmail.com' . "\r\n";
Related
I tried many alternatives to this code but it does not show my display name.
$to = $email;
$subject = $subject;
$message = $msg;
$headers = 'From: info#test.com \r\n';
$headers .= "Reply-To: info#test.com \r\n";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
try adding in the following convention.
$headers .= 'From: Mysitename <mysitename.com>' . "\r\n";
http://php.net/manual/en/function.mail.php
Ok I manage to make it work by re-arranging the headers, thanks for your input Ori.
$to = $email;
$subject = $subject;
$message = $msg;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
$headers .= 'From: Info <info#testsite.com>' . "\r\n";
How to check if mail was send or not using php ?
I use this code for send email using php. It's work good.
But i want to check email send success or not, How can i do that ?
<?PHP
$to = "test#mail.com";
$subject = "test subject";
$message = "test message";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: SENDER <noreply#sender.com>' . "\r\n";
$headers .= 'Return-Path: return#sender.com' . "\r\n";
mail($to, $subject, $message, $headers, '-freturn#sender.com');
?>
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 <example#gmail.com>' . "\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.
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)
use
$mail= mail($to, $sub, $msg, $headers);
You dont need string as all variables are Already string.
Use this mail($to, $sub, $msg, $headers),
If it returns true, then check your spam folder.
Write your domain name
$headers .= 'From: Your name <example#yorudomainname>' . "\r\n";
example <example#stackoverflow.com/>
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: webmaster#example.com" . "\r\n" .
"CC: somebodyelse#example.com";
$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: webmaster#example.com" . "\r\n" .
"CC: somebodyelse#yourdimain.com"; // enter your domain email
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
By mistake, I added from-address as to-address in mail-function.
It sends mail to both to-address and from-address why? Is it documented anywhere?
$from = 'from_user#gmail.in';
$to = 'to_user#gmail.com';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: ' . $to . "\r\n";
$headers .= 'From: ' . $from . "\r\n";
$message = json_encode(compact('to', 'from', 'headers'));
// NOTE THE FROM INSTEAD OF TO
mail($from, $subject, $message, $headers);
Further to the comments and to highlight your request for reference. Here is a snippit from the php manual for reference. Notice the first line of additional headers:
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: Mary <mary#example.com>, Kelly <kelly#example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
So you are sending an email both through the mail($to... (which happens to be the $from in your case) but you are also sending the $to in the $headers declaration.
I am attempting to send an email using the mail() PHP function. I had it working until I attempted to give it a subject of "User registration", then the mail is not sent!
Heres the code (have simplified it greatly)
$to = $this->post_data['register-email'];
$message = 'Hello etc';
$headers = 'From: noreply#example.com' . "\r\n" ;
$headers .= 'Content-type: text/html; chareset=iso-8859-1\r\n';
$headers .= 'From: Website <admin#example.com>';
mail($to, 'User Registration', $message, $headers);
I also attempted to use a variable containing the string of text but that didnt work.
Why is it not sending the mail when I add the subject exception?
Thanks
EDIT: updated code thats still not working
$to = $this->post_data['register-email'];
$message = 'Hello etc';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= 'From: Website <admin#example.com>';
mail($to, 'User Registration', $message, $headers);
On your 4th line you're using ' that handles everything inside of it as a string so change
$headers .= 'Content-type: text/html; chareset=iso-8859-1\r\n';
To:
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
and as mentioned in the comments change chareset to charset
Edit:
if your sending a txt/html mail you have according to documentation to set mime in the headers too so try this
$to = $this->post_data['register-email'];
$message = 'Hello etc';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= 'From: Website <admin#example.com>' . "\r\n";
mail($to, 'User Registration', $message, $headers);
If it still doesn't work you could try to debugg your code, simply add
error_reporting(E_ALL);
ini_set('display_errors', '1');
on top of the page, and take it from there, and if you still can't solve it by yourself post it here and I'll do my best to help ya out.
I'm using this code on most of my projects:
$subject = 'subject';
$message = 'message';
$to = 'user#gmail.com';
$type = 'plain'; // or HTML
$charset = 'utf-8';
$mail = 'no-reply#'.str_replace('www.', '', $_SERVER['SERVER_NAME']);
$uniqid = md5(uniqid(time()));
$headers = 'From: '.$mail."\n";
$headers .= 'Reply-to: '.$mail."\n";
$headers .= 'Return-Path: '.$mail."\n";
$headers .= 'Message-ID: <'.$uniqid.'#'.$_SERVER['SERVER_NAME'].">\n";
$headers .= 'MIME-Version: 1.0'."\n";
$headers .= 'Date: '.gmdate('D, d M Y H:i:s', time())."\n";
$headers .= 'X-Priority: 3'."\n";
$headers .= 'X-MSMail-Priority: Normal'."\n";
$headers .= 'Content-Type: multipart/mixed;boundary="----------'.$uniqid.'"'."\n";
$headers .= '------------'.$uniqid."\n";
$headers .= 'Content-type: text/'.$type.';charset='.$charset.''."\n";
$headers .= 'Content-transfer-encoding: 7bit';
mail($to, $subject, $message, $headers);
I would suggest to use PHP_EOL instead of \r\n or \n as the line break would then be determined by your environment...
$headers = 'MIME-Version: 1.0' . PHP_EOL;
etc.. hoping this might finally solve your problem!