By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,349 Members | 1,353 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,349 IT Pros & Developers. It's quick & easy.

Problem with Mail() Function

P: n/a
The following simple script receives data from a form and sends me an
email. It works fine on my testing machine (xampp for windows).
However, when I upload it to my web host, the script processes but I
do not receive the email. I have used two different email addresses
and both work from the localhost and both fail from the web host. One
email address is at verizon.net and the other at gmail.com. I have
also checked the spam folders and the mail is not there.

I have emailed my webhost and they say that they tried the script and
it worked for them. They claim no problem with the server and suggest
that I check with my software manufacturer.

Web Host PHP version 5.2.5
Localhost PHP version 5.2.6

Any suggestions as to what may be going wrong?

Thanks for your help,

Tom

The Script:

<?php
$ln=$_POST['lname'];
$fn=$_POST['fname'];
$em=$_POST['email'];
$vat=$_POST['vatsim_id'];
$city=$_POST['city'];
$state=$_POST['state'];
$country=$_POST['country'];
$hub=$_POST['req_hub'];
$req_password=$_POST['req_password'];

// Send email to Tom Rushworth with details from pilot application

$mailto="??*****@gmail.com";
$mailsubject="CAA - New Member Application";
$mailbody ="An application to join CAA was completed with the
following information:" . "\n" . "\n";
$mailbody .= "Last name: " . $ln . "\n";
$mailbody .= "First name: " . $fn . "\n";
$mailbody .= "Email Address: " . $em . "\n";
$mailbody .= "VATSIM ID: " . $vat . "\n";
$mailbody .= "City: " . $city . "\n";
$mailbody .= "State: " . $state . "\n";
$mailbody .= "Country: " . $country . "\n";
$mailbody .= "Hub: " . $hub. "\n";
$mailbody .= "Password Requested: " . $req_password . "\n";

mail("$mailto", "$mailsubject", "$mailbody", "CAA NEW MEMBER
ANNOUNCEMENT");

// Retrurn to application

header("Location: pilot_application.php?app_submitted=yes");

?>
Aug 19 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
<comp.lang.php>
<Call Me Tom>
<Tue, 19 Aug 2008 17:38:03 -0400>
<u6********************************@4ax.com>
Any suggestions as to what may be going wrong?
ini_set("sendmail_from","we*******@rambo.co.uk");
ini_set("SMTP","pop.rambo.co.uk");

I once had some windows hosting where i had to use the above 2 lines
before the mail() command would work .

Although the chances are your using linux hosting .

But the point is it might be a configuration problem that can be fixed
with 'whatever' one line of ini_set code .
--
www.cannabisaware.co.uk
Aug 19 '08 #2

P: n/a
On Aug 19, 2:38 pm, Call Me Tom <No...@nowhere.netwrote:
The following simple script receives data from a form and sends me an
email. It works fine on my testing machine (xampp for windows).
However, when I upload it to my web host, the script processes but I
do not receive the email. I have used two different email addresses
and both work from the localhost and both fail from the web host. One
email address is at verizon.net and the other at gmail.com. I have
also checked the spam folders and the mail is not there.

I have emailed my webhost and they say that they tried the script and
it worked for them. They claim no problem with the server and suggest
that I check with my software manufacturer.

Web Host PHP version 5.2.5
Localhost PHP version 5.2.6

Any suggestions as to what may be going wrong?

Thanks for your help,

Tom

The Script:

<?php
$ln=$_POST['lname'];
$fn=$_POST['fname'];
$em=$_POST['email'];
$vat=$_POST['vatsim_id'];
$city=$_POST['city'];
$state=$_POST['state'];
$country=$_POST['country'];
$hub=$_POST['req_hub'];
$req_password=$_POST['req_password'];

// Send email to Tom Rushworth with details from pilot application

$mailto="????...@gmail.com";
$mailsubject="CAA - New Member Application";
$mailbody ="An application to join CAA was completed with the
following information:" . "\n" . "\n";
$mailbody .= "Last name: " . $ln . "\n";
$mailbody .= "First name: " . $fn . "\n";
$mailbody .= "Email Address: " . $em . "\n";
$mailbody .= "VATSIM ID: " . $vat . "\n";
$mailbody .= "City: " . $city . "\n";
$mailbody .= "State: " . $state . "\n";
$mailbody .= "Country: " . $country . "\n";
$mailbody .= "Hub: " . $hub. "\n";
$mailbody .= "Password Requested: " . $req_password . "\n";

mail("$mailto", "$mailsubject", "$mailbody", "CAA NEW MEMBER
ANNOUNCEMENT");

// Retrurn to application

header("Location: pilot_application.php?app_submitted=yes");

?>
When sending mail, you must supply a "From: " header. One way to do
it has already been mentioned on this thread: using the sendmail_from
configuration setting.

Another way to do it is to supply it via the 4th parameter to the
mail() function. What does "CAA NEW MEMBER
ANNOUNCEMENT" in your script mean? The 4th parameter needs to
contain proper MIME-encoded e-mail headers, which means something like
"From: no****@example.com".

So a possible way to debug your script would be: since it works fine
locally, take a look and see who the "From:" address is when you
receive the e-mail. If it's something you didn't specify anywhere in
your script, then it's probably being set via the sendmail_from
configuration setting.

(Also, depending on how your host is set up, additional e-mail headers
may be required. For example: on my web host, I have to set the
"Return-Path:" header in addition to the "From:" header. If I don't
set it, the e-mail doesn't get sent.)

Hope that helps.

Walter
Aug 19 '08 #3

P: n/a
Call Me Tom wrote:
email. It works fine on my testing machine (xampp for windows).
However, when I upload it to my web host, the script processes but I
do not receive the email.
Thats not the real Problem of youre code!
The code dont check and filter bad data by any way. Better put it to
your trash or repair it.
Aug 20 '08 #4

P: n/a
On 20 Aug, 09:40, Ulf Kadner <dr_lo...@gmx.netwrote:
Call Me Tom wrote:
email. It works fine on my testing machine (xampp for windows).
However, when I upload it to my web host, the script processes but I
do not receive the email.

Thats not the real Problem of youre code!
The code dont check and filter bad data by any way. Better put it to
your trash or repair it.
Not a problem since only hardcoded stuff is going in the headers - the
posted data only appears in the body. As long as he's not daft enough
to try and use MS Outlook it'll work fine.

It's overkill for debugging though - and as an illustration of what
does not work:

OP - cut down your code to the minimum necessary to reproduce the bug
before posting.

e.g.

<?php
mail("...@example.com", "hello world", "testing", "CAA NEW MEMBER
ANNOUNCEMENT");
?>

Although it may not be the reason its failing, your additional headers
are crap. Email headers should of type "label: value" where label is a
contigious string of letters, digits, hyphens and underscores -
further, if the label is not one of the declcared types in the
relevant RFCs, it should be prefixed by 'X-' e.g.

<?php
mail("...@example.com", "hello world", "testing", "X-test: CAA NEW
MEMBER
ANNOUNCEMENT");
?>
C.
Aug 20 '08 #5

P: n/a
<comp.lang.php>
<C. (http://symcbean.blogspot.com/)>
<Wed, 20 Aug 2008 09:10:21 -0700 (PDT)>
<f2**********************************@a70g2000hsh. googlegroups.com>
OP - cut down your code to the minimum necessary to reproduce the bug
before posting.
But if hes kinda new to php - and asking the question - then how does he
know one way or the other what code he should or shouldnt include ? .
--
www.phpguestbook.co.uk/phpgb
(the best php guestbook on planet earth)
Aug 20 '08 #6

P: n/a
On Wed, 20 Aug 2008 09:10:21 -0700 (PDT), "C.
(http://symcbean.blogspot.com/)" <co************@gmail.comwrote:
>On 20 Aug, 09:40, Ulf Kadner <dr_lo...@gmx.netwrote:
>Call Me Tom wrote:
email. It works fine on my testing machine (xampp for windows).
However, when I upload it to my web host, the script processes but I
do not receive the email.

Thats not the real Problem of youre code!
The code dont check and filter bad data by any way. Better put it to
your trash or repair it.

Not a problem since only hardcoded stuff is going in the headers - the
posted data only appears in the body. As long as he's not daft enough
to try and use MS Outlook it'll work fine.

It's overkill for debugging though - and as an illustration of what
does not work:

OP - cut down your code to the minimum necessary to reproduce the bug
before posting.

e.g.

<?php
mail("...@example.com", "hello world", "testing", "CAA NEW MEMBER
ANNOUNCEMENT");
?>

Although it may not be the reason its failing, your additional headers
are crap. Email headers should of type "label: value" where label is a
contigious string of letters, digits, hyphens and underscores -
further, if the label is not one of the declcared types in the
relevant RFCs, it should be prefixed by 'X-' e.g.

<?php
mail("...@example.com", "hello world", "testing", "X-test: CAA NEW
MEMBER
ANNOUNCEMENT");
?>
C.
Thanks for the comments and suggestions. It turns out that the code
woks fine. However, I do agree that the fourth parameter should be
proper headers and I have changed the code to correct that.

It turns out that the problem was that Verizon was blocking all email
from my host's server (at least the one that I am on) as spam. They
contacted Verizon and all is now OK.
Aug 21 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.