When I send a message with PHP the recipients gets a from address such as this one:
user123#p3nlhg147.shr.prod.phx3.secureserver.net
How can I use my custom email address like info#mydomain.com as sender address?
Part of the mail function is the ability to include headers.
You should send a From header, like so:
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
source: http://php.net/manual/en/function.mail.php
If you mean how to change the field From, use this snippet from the official doc:
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
Related
I've made a website with a mailing form, and the php to send it is as follows:
<?php
$to = "example#outlook.com";
$subject = $_POST["subject"];
$message = $_POST["message"];
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
It won't send anything.
Can anyone tell what's wrong in the script?
If it helps on anything, I'm trying to send to an Outlook email.
Thanks
I have a script that sends an email, but instead of the sender name being "admin#foo.bar", I want it to say "Foobar Admin". How can I do this?
Thanks!
Do you want something like this??
$email_from = $full_name.'<'.$email_from.'>';
try this
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
for reference use http://www.php.net/manual/en/function.mail.php
Use this;
<?php
$to = 'to#mail.com';
$subject = 'Your subject';
$message = 'Your message';
$headers = 'From: Foobar Admin<admin#foo.bar>' . "\r\n" .
'Reply-To: admin#foo.bar' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
mail("recipient#aol.com","subject","message","From:Foobar Admin<foobar#admin.com>");
Let me start by saying I do not have a lot of programming knowledge. I use a program called PHPRunner to generate most of the php that I do. It is mainly for small office stuff nothing fancy.
My question is:
I have a table that has 6 fields one of them called email. When I go into a record I wanted to put a button called "send notification" that would email the record details to the email address associated with that record.
Any help would be greatly appreciated. I know it is probably out here on the web, possibly searching the wrong way.
You can use the mail function in php. Example from the provided link:
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
For sending email using PHP, use mail() function
http://php.net/manual/en/function.mail.php
Example:
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$from = 'webmaster#example.com';
$headers = 'From: '.$from . "\r\n" .
'Reply-To: '.$from . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
i have to send email where email "from" having 'firstname''lastname'.
For ex: first_name="john"
last_name="Dime"
email_id="john#john.com"
then from should be like this in the sent mail: From: john dime.
Please help me if u find any solution.
As per RFC 2822, you simply need to set a header of the form...
From: John Dime <john#john.com>
...in the headers portion of your email.
I have found instances of mail not being delivered correctly if the from address is not specified using the -f option with sendmail:
<?php mail($email, $subject, $body, $headers, "-f $email") ?>
Yes simply write your name in "FROM" portion like given below
$headers = 'From: Fname Lname<webmaster#example.com>' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
This is taken from php.net website:
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
You can specify the from field in the additional headers.
You just need to change the webmaster#example.com with the desired string
http://php.net/manual/en/function.mail.php - this can be useful for you
here is my code....
$subject = "This is Subject";
$headers .= 'Content-type: text/html; charset=iso-8859-1';
$to = 'foo#foo.com';
$body = 'Mail Content Here';
mail($to, $subject, $body, $headers);
but when i open this file it sends a mail to $to successfully but with wrong headers....and my hosting server default address i.e mars.myhosting.com, instead of mydomain#domain.com how can i fix that
Look at this from php.net
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: Webmaster <webmaster#example.com>' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
Add the from header
Here is what I would do via PHP:
<?PHP
$to = 'email#address.com';
$subject = 'desired subject';
$message = 'desired message';
$headers = 'From: example#email.com' . "\r\n" .
'Reply-To: example#email.com' . "\r\n" .
'Return-Path: example#email.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
I hope that helps some :)