...

View Full Version : PHP's mail function not sending mail...



Paithar
11-06-2006, 09:41 PM
On another website I used PHP's mail function to mail a simple contact us type form to an admin person. Well, I have need of doing it with my current job. I created a simple contact us form and all it has to do is email it's contents to me (for testing of course).

Well, it's not returning any errors whatsoever but it's also not sending the email.

Here's the contact us form page... http://www.oasisgamingusa.com/testlayout/contactus_layout9.php

Here's the code for the actual page that has the mail function...

<?php
function handleform()
{
......... other code here ..........
} // end if action == 2
else
if(!$action)
{
// email the comments from the contactus page to
// the default email address
//$toaddress = "marketing@oasisgamingusa.com"
$toaddress="Sean.Meyer@oasisgamingusa.com";

// To send HTML mail, the Content-type header must be set
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: website@oasisgamingusa.com\r\n";

$subject = "Comments/Inquiry";

$mailcontent = "
<html>
<head>
<title>Comment/Inquiry From Website User</title>
</head>
<body>
<table>
<tbody>
<tr>
<td colspan='2'><h1>Comment/Inquiry From Website User</h1></td>
</tr>
<tr>
<td><strong>Name:</strong></td>
<td>$name</td>
</tr>
tr>
<td><strong>Email:</strong></td>
<td>$email</td>
</tr>
<tr>
<td><strong>Phone:</strong></td>
<td>$phone</td>
</tr>
<tr>
<td><strong>Comments/Inquiry:</strong></td>
<td>$comments</td>
</tr>
</tbody>
</table>
</body>
</html>";

if(!mail($toaddress, $subject, $mailcontent, $headers))
{
echo "<p class='articlecontent'>There was an error submitting ";
echo "your comments. Please try again later.</p>";
exit();
}

echo "<p class='articlecontent'>Thank you! We appreciate your ";
echo "comments and will contact you back if needed.</p>";
}

}
?>

That code actually does some other stuff as well but the mail function code is in the lower half.

Anyone know if there's something else that needs to be set up and where I might found out how to set it up?

Anyone have any other ideas for me on what might be wrong?

Thanks

littlejones
11-06-2006, 10:03 PM
Maybe I'm stupid but where abouts is the mail function used in that code to send the mail?

Paithar
11-06-2006, 10:18 PM
The mail function is towards the bottom of that code section. It's about 13 or so lines up from the bottom. Part of an if statement to see if it gets an error while sending.

I'm thinking the problem is actually on our server and the way the mail server is configured. I believe that our network guy said that it was set up in a DMZ. I'm not really sure what that means but evidently it makes a little more difficult to send mail via our mail server.

littlejones
11-06-2006, 10:27 PM
if(!mail($toaddress, $subject, $mailcontent, $headers))
{
echo "<p class='articlecontent'>There was an error submitting ";
echo "your comments. Please try again later.</p>";
exit();
}



I'm not exactly a php seasoned pro but that almost looks to me like your saying what the code should do if mail is not sent, but not actually attempting to send it. I may well be wrong but try simplifying the code a little first just to rule out the possibility that the code could be wrong, then you'll know for sure that it's the server.




$toaddress="Sean.Meyer@oasisgamingusa.com";
$subject = "Comments/Inquiry";
$mailcontent = "Just testing to see if this works...";

if($_SERVER['REQUEST_METHOD'] == 'POST')
{
mail($toaddress,$subject,$mailcontent);
}


That's probably the quickest way to find out if your code is dodgy.

Paithar
11-06-2006, 10:32 PM
Ok, I'll give that a try and see what happens.

At one time I did try it without the if statement and just had the mail function and it still acted like it sent, giving me no errors whatsoever, but I didn't receive anything.

Anyway, my day is done so I'll try this out tomorrow.

Thanks for the input though.

littlejones
11-06-2006, 10:35 PM
Good luck with it, and if you have time to let us know how it goes then I'd appreciate it :thumbsup:

johnnyb
11-06-2006, 11:19 PM
I'm not exactly a php seasoned pro but that almost looks to me like your saying what the code should do if mail is not sent, but not actually attempting to send it. I may well be wrong but try simplifying the code a little first just to rule out the possibility that the code could be wrong, then you'll know for sure that it's the server.


The code:
if(!mail($toaddress, $subject, $mailcontent, $headers)) will actually try to send the mail, then, if it is successful will return a false, (because of the ! ), and if unsuccessful return a true and post the error message.

However, the solution of simplifying the code will help a lot because with the current structure you won't see the error messages.

Paithar
11-07-2006, 08:08 PM
Well, I tried the simpler solution above as well as a couple of other ideas I had and still I receive no emails. After talking more to our MCSE guy more I'm almost positive the problem is not with my code but with how things are set up here internally (ie with the mail servers and firewall and what not). We're going to work on it and see what we can come up with here.

Thanks for all the help though everyone. I appreciate it.

mlseim
11-07-2006, 08:22 PM
Don't forget to check your bulk bin (junk bin/spam bin) whatever yours
is called ... sometimes emails get in there and you forget to look.

rafiki
11-07-2006, 11:07 PM
also, subjects are known for sending non-spam emails to junk inbox, try changing your subject

Paithar
11-08-2006, 01:46 PM
Thanks for the info. I'll definitely check those things just to make sure.

kaisellgren
11-08-2006, 02:05 PM
firstly you can try to make a new script like this and execute it once:


<?php
mail("yourmail@mail.com","subject","message");
?>
Remember to change the yourmail to the correct so you can see whether it succeed or not.

Check also that mail() function is enabled in the php.ini and check out also that you can SMTP server established.

rafiki
11-08-2006, 05:27 PM
in addition on checking if the mail sends
create a new document named testmail.php
with this is



<?php
$time = time();
$to = "you@youremail.com";
$subject = "test subject";
$body = "this should be sent to $to, with the subject line of $subject at $time" ;

mail($to, $subject, $body);
if (mail($to, $subject, $body))
{
echo "the test mail was sent";
}
else
{
echo "the test email failed to send";
}
?>



this will tell you if the mail was sent, dont forget to change the email again :P

rafiki
11-08-2006, 05:36 PM
heres a page with the exact code on tripod
http://members.lycos.co.uk/jaysphp/testmail.php
you may need to view source coz of the ads

fan
11-09-2006, 08:26 AM
heres a page with the exact code on tripod
http://members.lycos.co.uk/jaysphp/testmail.php
you may need to view source coz of the ads

rafiki, how can you view the source of a PHP page (read server-side generated and passed to the browser) in a browser? :D

I guess that thing doesn't send you an e-mail everytime someone goes to the page, does it?

rafiki
11-09-2006, 09:03 AM
i meant view the source 2 see wat the echo sent (to see if mail sent) and yhe everytime s ome1 goes on there it will send a mail, but i will be deleting page very soon



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum