Avatar of PHP123
PHP123
 asked on

Sending Email in PHP

Hi,

    I am using the following PHP code to send an email

$to = 'me@hotmail.com';
$from = 'you@yahoo.com';
$subject = "Subject";
$mailbody = "Content"

$mailforms = mail($to, $subject, $mailbody, $from);

  Problem is , when i receive an email  it has the "From address" set to "Apache" my sever default instead of "you@yahoo.com".How can i resolve this problem?

Thanks in Advance.


Web Languages and Standards

Avatar of undefined
Last Comment
COBOLdinosaur

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
3MAN8

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
liquidblaze

you would like to code it like this:

mail($receiver,$subject,$message,"From: $sender","X-mailer: $mailclient","X-Priority: $prior_1","X-MSMail-priority:$prior_2"))

where:

$sender would be smthg like you@yourdomain.tld
$mailclient - normally used to pass on that it was mailed from within a php script, but you can set anything here like "my cool mail tool"
$prior_1 would be 1, 2 or 3 with 1 being normal, 2 being medium and 3 being high
$prior_2 is only for microsoft - just have to write normal, medium or high there...

think that should do it
regards liquidblaze
rhei

The problem, that other people on the page tryied to explain is, that the $from parameter of the mail command is not the value of the 'From:' field in the mail header , but it modifies the mailheader lines according to the 'Value_name:' contained in the $from variable - referr to the RFC 2822 (rfc-editor.org) for more information for mail headers.
kamran65536

mail(to, subject, body, "From : from address");

the style is like this, I don't know weather writing "from : " or "From:" is correct or not, but this format works ;)
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
j79


$to = 'me@hotmail.com';
$from = 'you@yahoo.com';
$subject = "Subject";
$mailbody = "Content"


$mailforms = mail($to, $subject, $mailbody, "From: ".$from."\nReturn-path: <".$from.">\n");


$from can also be given from a html/php form page filled by the visitor.


j79




COBOLdinosaur

This question has been classified abandoned. I will make a recommendation to the
moderators on its resolution in a week or two. I appreciate any comments
that would help me to make a recommendation.

<note>
Unless it is clear to me that the question has been answered I will recommend delete.  It is possible that a Grade less than A will be given if no expert makes a case for an A grade. It is assumed that any participant not responding to this request is no longer interested in its final disposition.
</note>

If the user does not know how to close the question, the options are here:
https://www.experts-exchange.com/help/closing.jsp


Cd&