php mail not showing senders email address - php

I¨ve got a problem answering mails sent from my website, as the senders emailaddress isn´t showing anywhere, only the webmasters email
Here is my code:
<?php>
$from="kim.s.nielsen#mail.dk";
$email="info#intotext.dk";
$name=$_POST['name'];
$message=$_POST['message'];
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: ' . $fromName . ' <' . $fromEmail .'>' . " \r\n" . 'Reply-To: '. $fromEmail . "\r\n" . mail($email, $name, $message, $headers);
print"Din besked er sendt. Vi vender tilbage så hurtigt som muligt." ?>

Use this format to send your email, this will show the senders email address, try this. you have concatenated the mail function with your header, mail() is not header it is used to send your email.
$fullname = "full name";
$from = "sender#mail";
$to = "reciever#mail";
$subject = "Your subject";
$message = "<h1> heading </h1><p> Message </p>";
$headers = [
'MIME-Version: 1.0',
'Content-type: text/html; charset=iso-8859-1',
'From: ' . htmlspecialchars($fullname) . " <$from>",
'X-Mailer: PHP/' . phpversion()
];
mail($to,
htmlspecialchars($subject),
nl2br(htmlspecialchars($message)),
implode("\r\n", $headers)
);

Related

How can i add cc to mail function? [duplicate]

This question already has answers here:
PHP Mail, CC Field
(3 answers)
Closed 7 years ago.
this is my code, But i am getting blank mails also. what was the wrong with this?
'success',
'message'=>'Thank you for contact us. As early as possible we will contact you '
);
$name = #trim(stripslashes($_POST['name']));
$email = #trim(stripslashes($_POST['email']));
$subject = #trim(stripslashes($_POST['subject']));
$message = #trim(stripslashes($_POST['message']));
$email_from = $email;
$email_to = 'To: <someone#gmail.com>, <anotherone#gmail.com>' . "\r\n";
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;
$success = #mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
die;
Please read documentation mail function Here they explained detailedly.
Particularly Example #4 Sending HTML email
$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);

Sending email headers

I have such code for send email:
$email = $_POST['message_email'];
$headers = 'From: '. $email . "\r\n" .
'Reply-To: ' . $email . "\r\n";
before that I check whether the email is correct so it has to be.
Then I send an email:
$sent = wp_mail($newTo, $subject, $companyName . "\n" . $email . "\n" . $phoneNumber . "\n" . strip_tags($message) . "\n" . $outputMail, $headers);
and it doesn't work. I've tried change headers to:
$headers = 'From: My Name <myname#mydomain.com>' . "\r\n\\";
and then it works. Why my code does't work? I need to provide that email retreived from form.
Try like this:
****Ive edited the code****
$from = "your#mail.com";
$to = "to#mail.com";
$message = "Message";
$subject = 'subject';
$headers = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=UTF-8' . "\r\n";
$headers .= "From: ".$from."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
if(mail($from, $subject, $message, $headers)){
//success
}else{
//error
}

Error in Sending Email using php

I am sending email using php script and i am setting from address as
$headers = "MIME-Version: 1.0" . "$from" . "\r\n";
$headers.= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
So, the mail coming to my mail address as from support#mysite.com, But i need to set from address as support#gmail.com.But it is not coming with the modified from address. So, please help to solve this problem..
You try this...
<?php
$to = 'nobody#example.com';
$subject = 'Mail Subject';
$message = 'Test';
$headers = 'From: support#gmail.com' . "\r\n" .
'Reply-To: support#gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
Hop this will works...
Replace header text,
$headers = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=UTF-8' . "\r\n";
$headers .= "X-Mailer: PHP \r\n";
$headers .= "From: YourName <support#gmail.com>";
To get more information about mail function
may this help you.

PHP Mail not formated for some reason

I am new to PHP and send an email using following code
<?php
$to = 'to#xyz.com';
$subject = 'the subject';
$message = '<table dir="rtl"><tr><td>'. "\r\n";
$message .= '<b>This is Bold</b></br> <i> This is Italics</i></br>شطب 14 مرشحا لمجلس الأمة الكويتي'. "\r\n";
$message .= '</td></tr></table>';
//Headers
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
$headers .= 'Content-Transfer-Encoding: quoted-printable' . "\r\n" .
$headers .= 'From: from#xyz.com' . "\r\n";
$headers .= 'Reply-To: replyto#xyz.com' . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
ini_set ( "SMTP", "smtp.xyz.com" );
mail($to, $subject, $message, $headers);
?>
I can receive the email and it display the arabic also but it also show the from email address in the body of the email.
And other issue is that arabic is RTL even after mentioning in table dir-"RTL" it still show the message as LTR.
Example of Email Received
from#xyz.com
This is Bold
This is Italics
شطب 14 مرشحا لمجلس الأمة الكويتي
You could try using the alternative of CSS2 style:
style="direction:RTL; unicode-bidi:embed;"
Extra reading: http://www.i18nguy.com/markup/right-to-left.html

Why is the From line not working on my mail function?

I am using a mail function to send html to an email address, but the From name and email address aren't showing up. This is my code:
$name = $_POST['name'];
$mailTo = 'name#email.com';
$subject = 'Message from ' . $_POST['name'];
$message =
'<html>
<head>
<title>HTML email</title>
</head>
<body>
<p><b>Name:</b> ' . $_POST['name'] . '</p>
<p><b>Email:</b> ' . $_POST['email'] . '</p>
<p><b>Message:</b> ' . $_POST['mainmessage'] . '</p>
</body>
</html>';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Postmaster <some#body.com>';
mail($mailTo, $subject, $message, $headers);
I would expect the email to show up as being from Postmaster at the email address some#body.com, but it is showing up as coming from ideapale#box486.bluehost.com, which is my hosting provider.
What did I not set up correctly?
Chris, try adding the \r\n after the <some#body.com>. I've found that php can be very picky when talking to mail servers.
Edit: just to help a little more, I have this (almost exactly what you have) in one of my working scripts:
$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";
...where $from = $fromname.' <'.$fromemail.'>'; and $to is just an email address.

Categories