/    Sign up×
Community /Pin to ProfileBookmark

Mail header not getting picked up

For some strange reason, the mail function won’t pick up the headers I give it. Here’s the code.

[code=php]$headers = “From: $email”;
$emailContent = “Name: $namenn Comments:n$comments”;
$emailResult = mail(“[email protected]”, $subject, $emailContent, $headers);
[/code]

All the variables do exist. Besides the From header, I’ve also tried Reply-To. No difference. Are there any server or PHP version limitations I’m not aware of? This server is running PHP 4.4.1

to post a comment
PHP

10 Comments(s)

Copy linkTweet thisAlerts:
@NogDogFeb 15.2008 — It may be a [b]sendmail_from[/b] setting in your PHP configuration. You may not want to override this, as many mail servers will only send mail from valid email accounts on that server. If that's the case, just set a "Reply-To:" header instead of "From:".
Copy linkTweet thisAlerts:
@nemesis_256authorFeb 15.2008 — I have tried Reply-To. Doesn't seem to work either. The sendmail_from setting is in the php.ini file right? I don't think I have access to it, the host is value web.
Copy linkTweet thisAlerts:
@NogDogFeb 15.2008 — You can see what it is set to by doing:
[code=php]
<?php
echo get_ini('sendmail_from');
?>
[/code]

It can be overridden locally via .htaccess (if allowed), or via an ini_set() on a per-script basis.
Copy linkTweet thisAlerts:
@nemesis_256authorFeb 15.2008 — So I tried that, it changed the actual value, but it doesn't seem to work. I then read somewhere that the solution you provided only works with Windows. The server I'm on is some unix variation.

This problem is just annoying...thanks for the ideas though.
Copy linkTweet thisAlerts:
@nemesis_256authorFeb 18.2008 — I still haven't found a solution for this. Anyone else?
Copy linkTweet thisAlerts:
@TheRaveFeb 19.2008 — I had a similar problem about a year ago.

I ditched the mail() function and started using phpmailer.
Copy linkTweet thisAlerts:
@watermelonFeb 19.2008 — Here is the basic web form and works for me;

CONTACT.PHP PAGE;
<form id="frm_message" name="frm_message" method="post" action="send.php">

<table width="95%" border="1" cellpadding="3" bgcolor="#EEEEEE">

<tr>

<td><div align="left"><span class="style6">Your Email Address</span></div></td>

<td>

<div align="left">

<input type="text" name="emailAddress" id="emailAddress" />

</div>

</td>

</tr>

<tr>

<td><div align="left"><span class="style6">Subject</span></div></td>

<td>

<div align="left">
<input type="text" name="subject" id="subject" />
</div>
</td>
</tr>
<tr>
<td><span class="style6">Message Body</span></td>
<td>
<textarea name="messageBody" id="MessageBody" cols="55" rows="6"></textarea>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<input name="button" type="submit" id="button" onclick="MM_validateForm('emailAddress','','RisEmail','subject','','R');return document.MM_returnValue" value="Submit" />
</td>
</tr>
</table>[/QUOTE]


SEND.PHP page
<?php

$to = "yourname???@yourserver????.com";

$subject = $_POST['subject'];

$body = $_
POST['messageBody'];

$headers = "From: " . $_POST['emailAddress'] . "n";

mail($to,$subject,$body,$headers);

?>[/QUOTE]
Copy linkTweet thisAlerts:
@TheRaveFeb 19.2008 — @ Watermelon, the php mail() function may not process the headers correctly depending on the set-up of your server. For your server it is obviously set up to process the headers, for nemisis' and my server it is not. Hence why the mail() function is not processing them correctly.

Also:

php tag > quote tag (when posting php code)
Copy linkTweet thisAlerts:
@watermelonFeb 19.2008 — For your server it is obviously set up to process the headers[/QUOTE]

I also go to edit with "php.ini and save as

[mail function]

; For Win32 only.

SMTP = mail.yourserver???.com


; For Win32 only.

;sendmail_from = [email]webmaster@yourserver???.com[/email][/QUOTE]


Here that my process, if it does not work for you, will let someone with more experience help out..
Copy linkTweet thisAlerts:
@TheRaveFeb 19.2008 — You can only make that change if you have access to the ini file which with shared hosting you do not.

An alternative is to set it in the details in htaccess or directly in the script as NogDog said.

Or as another alternative use a fully functional SMTP mailer such as PHPMailer.
×

Success!

Help @nemesis_256 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...