473,406 Members | 2,849 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Problem with Mail() Function

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
6 1576
<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
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
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
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
<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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Bruce W...1 | last post by:
In my effort to learn PHP I'm playing with some simple email scripts. They worked a few days ago but they stopped working. The only thing I've done to this Windows 2000 PC in this time was a...
1
by: John | last post by:
Hi First of all apologies for posting so much code but this is rather involved and I am totally stumped. Basically I have a main form (Staff Batch SMS/E-Mail) which calls a function (SendSMS) in...
1
by: tangus via DotNetMonster.com | last post by:
Hello all, I'm really struggling with getting some Active Directory code to work in ASP.NET. Can you please provide assistance? I am executing the following code: Dim enTry As DirectoryEntry =...
4
by: k.visube | last post by:
In my ASP application,i need to send a formatted text mail (i.e with newline characters). here in my application i used a function in javascript which construts the mail body sample snippet ...
0
Dormilich
by: Dormilich | last post by:
this is a follow-up thread to this one. http://bytes.com/topic/html-css/answers/863662-form-not-submitted-sometimes I figured out that the mail sending class triggers the described error....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.