I am unable to set header in php for from address I have tried all possible values :
The code below is correct but code is not attached to header .
It shows this as default from but does not change.
From : webhost:cpanel#hosting
Is this the problem with cpanel ?
Please help me out really appreciate the help.
Thanks in Advance.
<?php
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$phone = $_REQUEST['contact'];
$subject = "feedback";
$question = $_REQUEST['question'];
$body = "<html>
<head>
</html>";
$mime_boundary = "<<<--==+X[".md5(time())."]\r\n\r\n";
$headers = "MIME-Version: 1.0"."\r\n" ."Content-Type:text/html;"."\r\n";
$headers .= 'From:'.$email. "\r\n";
$to ='example#example.com';
mail($to,$subject,$body,$headers);
echo "<script>alert(' message sent.');</script>";
?>
also tried :
<?php
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "From: Sender Name <sender#domain.com>";
$headers[] = "Reply-To: Recipient Name <receiver#domain3.com>";
$headers[] = "Subject: {$subject}";
$headers[] = "X-Mailer: PHP/".phpversion();
mail($to, $subject, $email, implode("\r\n", $headers));
?>
Only this works:
$to ='example#example.com';
$subject="subject";
$body="body";
$mime_boundary = "<<<--==+X[".md5(time())."]\r\n\r\n";
$headers = "MIME-Version: 1.0"."\r\n" ."Content-Type:text/html;"."\r\n";
mail($to,$subject,$body,$headers);
try this :
$to = 'me#gmail.com';
$subject = "Email from me by: John";
$body = "my body";
$headers = "From: "."hello#world.com"."\r\n" .
"Reply-To: "."hello#world.com"."\r\n".
"X-Mailer: php";
$sent=mail($to, $subject, $body, $headers);
if ($sent) {
echo "good!";
} else {
echo("<p>Message delivery failed...</p>");
}
Related
I'm looking for a solution to put the e-mail's header like address, subject, date etc... Into the e-mail's message body. Like it works when forwarding an e-mail from any e-mail client.
Is there a good practice for it in PHP? I couldn't find it in the manual.
I'm using php with laravel.
$to = 'me#mydomain.com';
$subject = 'Subject';
$headers = "From: me# mydomain.com\r\n";
$headers .= "BCC: someonelese# mydomain.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message .= "<html><body>…Email Message 1…</body></html>";
mail($to, $subject, $message, $headers);
}
if(count($errors) == 0) {
$to = ($_POST['email']);
$subject = 'Subject';
$url = 'mydomain.caom';
$headers2 = "From: me# mydomain.com\r\n";
$headers2 .= "BCC: someonelese# mydomain.com\r\n";
$headers2 .= "MIME-Version: 1.0\r\n";
$headers2 .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "<html><body>…Email Message 2…</body></html>";
mail($to, $subject, $message, $headers2);
echo '<META HTTP-EQUIV=Refresh CONTENT="1; URL='.$url.'">';
}
Can I just concatenate the headers into the body?
Yes you can!
You can do something like this
$to = 'me#mydomain.com';
$subject = 'Subject';
$headers = "From: me# mydomain.com\r\n";
$headers .= "BCC: someonelese# mydomain.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message_headers = str_replace("\r\n", "<br>", $headers);
$message = "<html><body>…Email Message 1…{$message_headers}</body></html>";
mail($to, $subject, $message, $headers);
The above will replace the new lines (\r\n) in $headers with the HTML <br> tag and the formatted headers will be added to the $message just before the closing <body> tag.
Also notice that I have removed the . from the $message .= "..."; and replaced it with $message = "...";
You dont need the . unless you are appending the $message variable.
I am using this basic php code to send out a html email.
When i use email#email.com as a to address the script works.
However, when i try to use email.2015#gmail.com the script says:
Parse error: syntax error, unexpected '#' in /home/u925912002/public_html/send_email.php on line 3
My code:
<?php
$to = ‘email.2015#gmail.com’;
$subject = 'I need to show html';
$from ='example#example.com';
$body = '<p style=color:red;>This text should be red</p>';
ini_set("sendmail_from", $from);
$headers = "From: " . $from . "\r\nReply-To: " . $from . "";
$headers .= "Content-type: text/html\r\n";
if (mail($to, $subject, $body, $headers)) {
echo("<p>Sent</p>");
} else {
echo("<p>Error...</p>");
}
?>
please can someone show me what i'm doing wrong. thanks
For your question recently closed: https://stackoverflow.com/questions/34106770/send-email-using-php-from-address-not-working
Try this:
$headers .= "From: Your Name <$from>\r\n";
and you can also add the 5th mail parameter:
mail($to, $subject, $body, $headers, '-finfo#userforum.com').
Works for me with these headers:
$from = "$name <$email>\r\n";
$to = "$username <$useremail>\r\n";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= "From: $name <$email>\r\n";
$headers .= "Reply-To: $name <$email>\r\n";
you are using Apostrophe(‘) instead of quotes(')
try this -
$to = 'email.2015#gmail.com';
instead of this -
$to = ‘email.2015#gmail.com’;
While I am sending any mail, this will return only name: from: message: subject : , but all these fields remain blank..
<?php
$name = #trim(stripslashes($_POST['name']));
$from = #trim(stripslashes($_POST['email']));
$subject = #trim(stripslashes($_POST['subject']));
$message = #trim(stripslashes($_POST['message']));
$to = 'me#example.com';
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "From: {$name} <{$from}>";
$headers[] = "Reply-To: <{$from}>";
$headers[] = "Subject: {$subject}";
$headers[] = "X-Mailer: PHP/".phpversion();
mail($to, $subject, $message, $headers);
die;
Without knowing your environment, mail function accepts the headers argument as a string, not an array.
mail($to, $subject, $message, implode("\r\n", $headers));
http://php.net/manual/en/function.mail.php
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
This is my sendemail.php. It is not working. Are there any mistakes on it ?
<?php
$name = #trim(stripslashes($_POST['name']));
$from = #trim(stripslashes($_POST['email']));
$subject = #trim(stripslashes($_POST['subject']));
$message = #trim(stripslashes($_POST['message']));
$to = 'richardhenokh#gmail.com';//replace with your email
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "From: {$name} <{$from}>";
$headers[] = "Reply-To: <{$from}>";
$headers[] = "Subject: {$subject}";
$headers[] = "X-Mailer: PHP/".phpversion();
mail($to, $subject, $message, $headers);
die;
try this. It is working fine
<?php
$name = #trim(stripslashes($_POST['name']));
$from = #trim(stripslashes($_POST['email']));
$subject = #trim(stripslashes($_POST['subject']));
$message = #trim(stripslashes($_POST['message']));
$to = 'imaphpdeveloper#gmail.com';//replace with your email
$headers = "MIME-Version: 1.0";
$headers .= "Content-type: text/plain; charset=iso-8859-1";
$headers .= "From: {$name} <{$from}>";
$headers .= "Reply-To: <{$from}>";
$headers .= "Subject: {$subject}";
$headers .= "X-Mailer: PHP/".phpversion();
mail($to, $subject, $message, $headers);
die;
?>
Also you can try PHPmailer. headers should be a string not an array. Also {$from} etc.. in headers should be replaced properly. Now using above code mail is sending. But have to replace {$from} properly.
I am using PHP mail and trying to send BCC, but for some reason since I've added the lines with //ADDED NEW on it , it's just now sending any emails at all.
Here is the full code:
$to = "me#gmail.com";
$bcc = $row['recipients']; //ADDED NEW
$subject = $row['subject'];
$message = $row['text_body'];
$headers = "From: " . strip_tags('me#gmail.com') . "\r\n";
$headers .= "Reply-To: ". strip_tags('me#gmail.com') . "\r\n";
$headers .= "Bcc: $emailList\r\n"; //ADDED NEW
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail($to, $bcc, $subject, $message, $headers); // $bcc ADDED NEW
Why is this not sending?
Your problem,
Set $bcc but in $headers does not using it
Putting invalid argument into mail function.
Try this
$to = "me#gmail.com";
$bccList = $row['recipients']; //ADDED NEW
$subject = $row['subject'];
$message = $row['text_body'];
$headers = "From: " . strip_tags('me#gmail.com') . "\r\n";
$headers .= "Reply-To: ". strip_tags('me#gmail.com') . "\r\n";
$headers .= "Bcc: $bccList\r\n"; //ADDED NEW
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail($to, $subject, $message, $headers); // $bcc ADDED NEW
There's no $bcc argument to the mail() function. It should be:
mail($to, $subject, $message, $headers);
The blind recipients will be retrieved from the Bcc header in $headers.