Configuration send mail for send my from - php

I setup sendmail in linux server, I use my gmail.com accaunt as mail collector. I can send mail to different mail address in web, but I can not set my field from: in mail, the from: always set as my mail address... How to I can set my custom email address on field from: in mail?
p.s. sorry for my English.

You can do this by setting header as:
$headers = 'From: username#domain.com' . "\r\n" .
'Reply-To: username#domain.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
Then you can use:
mail($to, $subject, $body, $headers) to send mail where $to, $subject and $body are self explanatory variables.
For more info: visit http://php.net/manual/en/function.mail.php

Related

PHP send mail through postfix

I have Postfix and SquirrelMail configured on my server. And user called noreply. So, I am logging to SquirrelMail and sending email to some address. Everything works fine, i am receiving email from noreply#mydomain.com. But when I try to send email from php using mail(),
mail ('test#2ether.net', 'Postfix Test', 'A test email');
server tries to send it from address www-data#mydomain.com. How do I configure it to send emails from noreply#mydomain.com?
I would use PEARMail it is designed to counter such issues, (PHP's "mail()" method is all but useless in today's email meta - too many bots used it ) however the actual answer is this:
$to = 'test#2ether.net';
$subject = 'Postfix Test';
$message = 'A test email';
$headers = 'From: noreply#mydomain.com' . "\r\n" .
'Reply-To: noreply#mydomain.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);

Message containing bare lf's

I have a problem with sending mail from PHP.
$to = 'admin#****';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#****' . "\r\n".
'Reply-To: webmaster#****' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers)
When I run this simple example script, or basically any tutorial script, I get the following error from hMailServer 554 Rejected - Message containing bare lf's.
I know this is due to a setting in hMailServer, but I don't want to turn off the RFC compliance check, I want to send correctly formatted mails.
Can you help me figure out what's wrong?

mail() method using PHP, how do I set the sender?

I'm using iPage for my website, and I'm using a simple mail() method to send test mails from my page. On iPage, I have email capabilities via mark#domain.com. But when I send an email out, it comes from the iPage server and is sent from ipg.domain#boscustweb3506.eigbox.net, which is quite ugly looking!
Is there a way I can use the mail() method in php to send an email from my page that will use the shorter sender above? Thanks for any and all help!
you need to add a header named From. this code will send with the mail address webmaster#example.com:
$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);
Try this, You can add the From header to customise the sender address.
$from ='mark#domain.com';
$headers = 'From: ' . $from . "\r\n";
...
mail($to, $subject, $message, $headers);

Sending mail from localhost using PHP

I am trying to send mail from localhost using PHP. I am using the following code to send the mail :-
<?php
$to = 'o****e#gmail.com';
$subject = 'hey You';
$message = 'Can you identify me :P';
$headers = 'From: at*****t#gmail.com' . "\r\n" .
'Reply-To: at*****t#gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
At first, I tried to send the mail to myself(at*****t#gmail.com), it worked fine. However, after that, now if I am changing the $to, its still sending the mail to same ID(mine) with the previous contents(not the updated one).
Is my request getting cached somehow ? Why every mail is being repeatedly sent to me irrespective of change in both contents and $to ?
Go to your php.ini file and change SMTP = localhost to SMTP = aspmx.l.google.com and uncomment sendmail_from and put in your sending gmail address. and set smtp_port = 25
Restart localhost

how to send email where "from" having 'firstname'<space>'lastname'<email_id> in php

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

Categories