Sendmail error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

renaxgade
Forum Newbie
Posts: 17
Joined: Wed Oct 29, 2003 4:02 pm

Sendmail error

Post by renaxgade »

I have a form and it POSTS to Mail.php, Mail.php looks like:

Code: Select all

<?php
$to = "**@*.net"
$subject = "icon";
$body = $_POST['name'] + "\n\r" + $_POST['sn']";
$from = "From: Joey<Wesite@LAL.com>\n";
$headers = $from;
mail($to, $subject, $body, $headers);
?>
It just does not want to mail to me. I have of course replaced the stars with my e-mail, its just for security. I have started sendmail in init.d, and it's in php.ini. HELP ME!
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Code: Select all

$body = $_POST['name'] + "\n\r" + $_POST['sn']";
you have an extra quote

make it

Code: Select all

$body = $_POST['name'] + "\n\r" + $_POST['sn'];
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

LiLpunkSkateR wrote: make it

Code: Select all

$body = $_POST['name'] + "\n\r" + $_POST['sn'];


Shouldn't it be....

Code: Select all

$body = $_POST['name'] . "\n\r" . $_POST['sn'];
...it's PHP not JavaScript.
renaxgade
Forum Newbie
Posts: 17
Joined: Wed Oct 29, 2003 4:02 pm

Post by renaxgade »

Nope. It works, but I don't get an e-mail.
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

You also need to escape the newline character.

Code: Select all

// THIS IS WRONG
$from = "From: Joey<Wesite@LAL.com>n"; 

// THIS IS CORRECT
from = "From: Joey<Wesite@LAL.com>\n"; 

// THIS IS BETTER
from = "From: Joey<Wesite@LAL.com>\r\n";
renaxgade
Forum Newbie
Posts: 17
Joined: Wed Oct 29, 2003 4:02 pm

Post by renaxgade »

Still get no e-mail. It doesnt really matter of the address its from right? Maybe my php.ini isnt configured right, or my sendmail is just not right. >< >< >< ><
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

Try a very basic email to see if it's a coding problem or a server/settings problem.

Code: Select all

<?

mail("you@somewhere.xxx", "Test Email", "This is a test.", "From:anyone@anywhere.xx");

?>
Obviously change the you@somewhere.xxx to your email address.... don't worry about the From: for now as you can put any email in there valid or not.
renaxgade
Forum Newbie
Posts: 17
Joined: Wed Oct 29, 2003 4:02 pm

Post by renaxgade »

Ok, I made that and went to it in a browser, but nope, I don't get an e-mail.
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

Then I suggest you contact your web host and let them know that you can not send any emails from PHP using mail().
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

maybe you're email service is just crap??
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

LiLpunkSkateR wrote:maybe you're email service is just crap??
That's a bit harsh 8O :wink:
renaxgade
Forum Newbie
Posts: 17
Joined: Wed Oct 29, 2003 4:02 pm

Post by renaxgade »

It's my own server.
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

renaxgade wrote:It's my own server.
Have you got an Email Server set up?
renaxgade
Forum Newbie
Posts: 17
Joined: Wed Oct 29, 2003 4:02 pm

Post by renaxgade »

I think the one that came with Redhat (sendmail) but other thatn that, no.
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

I don't know Redhat so my help ends here. It definatly sounds like an Email Server configuration problem though so that's where you will need to start looking.
Post Reply