Forum Moderators: coopster

Message Too Old, No Replies

PHP form --> mail not sending mail

Seeking for solution of a mail() problem in PHP.

         

Sastian

11:13 am on Dec 17, 2003 (gmt 0)

10+ Year Member




Hello all!

I'm new here and also I'm new to PHP - that's an important information.
The problem I've got is a problem with PHP script sending mail. Perhaps it is a question which I should post to a 'mail' group, however since it is connected with PHP I decided to give it a shot and post it here.

Now, about the problem:
I wrote a simple form where you input some data, send it to php script, which then in turn mails the data in a message.

Here's what the sources look like:

--- FORM.HTML ---

</HEAD>
<BODY bgcolor="#3162A3" text="#CAD9EE" link="#CAD9EE" vlink="#CAD9EE" alink="#CAD9EE">
<p align="left"><font color="#CAD9EE" size="3" face="Verdana"><B>ZGŁOSZENIE SZKODY</font></B></p>

<FORM METHOD=POST ACTION="form_mail.php">

<p align="LEFT"><font color="#CAD9EE" size="2" face="Verdana"><b>OSOBA POSZKODOWANA</b></font></p>

<p align="LEFT">
<TABLE border="0" cellpadding="10" cellspacing="0" width="65%">
<TR>
<td>
<p align="right"><font color="#CAD9EE" size="2" face="Verdana">Imię i nazwisko:</font></p>
</td>
<td>
<INPUT TYPE="TEXT" size="51" NAME="Client_name">
</td>
</tr>
</TABLE>
</BODY>
</HTML>

--- FORM_MAIL.PHP ---

<?php
$MailTo="recipient@server";
$MailSubject="Zgłoszenie";
$MailBody = "$_POST[Client_name]";
echo($MailTo, $MailSubject, $MailBody, "From: sender@server");
?>

---

And I don't get any mail (my address is put as $MailTo variable).

The apache error_log doesn't show any abnormalities save for "PHP notice: Undefined index: Client_name in /var/www/htdocs/form_mail.php", but I don't think this one's a serious one.

Now, another log I took a look at is the maillog (Sendmail's the MTA). Here the output from the log:

Dec 17 11:33:16 server sendmail[22629]: hBHAXG4i022629: from=nobody, size=131, class=0, nrcpts=0, msgid=<200312171033.hBHAXG4i
022629@server.coris.com.pl>, relay=nobody@localhost

- means the message was not sent. But what could be the problem? Did any of you encounter similar problems with using mail()?

It would be advisable to add, that I also tried to send a message using the form_mail.php script itself. And I think it's the Sendmail that might be the problem.

Any hints? All will be appreciated.

Best regards to you all,
Sebastian

coopster

12:52 pm on Dec 17, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, Sastian!

The first thing I noticed is that you are using the echo function as opposed to the mail function, which would be quite obvious why your mail is not sending, but this may be something you were using during testing and forgot to change before you cut and paste your code. Can you confirm?

Also change your $MailBody variable assignment as follows and it should get rid of the notice error:


$MailBody = $_POST['Client_name'];

You can read more about how to format these types of variables in the PHP Manual Array do's and don'ts [php.net].

Sastian

1:36 pm on Dec 17, 2003 (gmt 0)

10+ Year Member



Coopster,

Thank you for your warm welcome :-)

I confirm that, indeed, I made a mistake while pasting the text and instead of echo there should be mail() function used.

As for the variable "$_POST[Client_name]" (which indeed should look like: $_POST['Client_name']) - I don't think that is quite the problem. I mean I made my script work calling this variable my way, but the problem seems to be the Sendmail which does not deliver the mail.

Anyway thank you for your suggestion, I will check that for the sake of peace of mind :-)

Thanks a lot!
Sebastian

coopster

1:58 pm on Dec 17, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Yeah, your script would still work, I was just helping you get rid of the NOTICE error. And I wanted to confirm that you had indeed attempted the mail function where your echo statement was, and you confirmed that.

To start troubleshooting , have you had a look at the runtime configuration settings on the PHP Mail functions [php.net] page? The User Contributed notes may also offer some tips.

coopster

2:15 pm on Dec 17, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You may also want to check the mail [php.net] function User Contributed notes. There is an entry in there that states:

...Some SMTP won't accept e-mail with the "From: host@domain" without the suffix "com", like "domain.com"...

I noticed you aren't using a domain extension on your email addresses. May be an issue?

Sastian

2:31 pm on Dec 17, 2003 (gmt 0)

10+ Year Member




Don't think so. The actual address I am using is person@server.com.pl, so there shouldn't be any problem.
Anyway I think my friend I work with solved the problem. Know what was the solution? I will tell you anyway :-)
He used the mail() function with a fifth option - which overrides the default sender's name, which - in Apache's case is 'nobody', with a name specified by admin.
The function looks like this now:

mail("Recipient", "Subject", "Message", "From: ", "-f postmaster@server.com")

We think the problem was caused by Sendmail not letting relay messages sent by user nobody@server.com. Therefore we changed the user's name from nobody to postmaster@server.com and it works allright now.
However to avoid Sendmail's notices saying that the name of the sender was changed we put a line like this to php.ini:

sendmail_path = /usr/bin/sendmail -t -i -f /
/ postmaster@server.com

What do you think about that?

Best regards,
Sebastian

coopster

2:43 pm on Dec 17, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



That's exactly why I posted the links for you -- the resolution you used is right there in the manual pages [php.net] and User Contributed notes [php.net]. The PHP manual pages really have a lot to offer.

Glad you resolved the issue, Sastian!

Sastian

2:45 pm on Dec 17, 2003 (gmt 0)

10+ Year Member




Actually, well, most peculiar! it sufficed to put the exact path to sendmail with the default switches:

sendmail_path = /usr/bin/sendmail -t -i

No override of client name was necessary.
A stupid mistake(?) which teaches and reminds how small errors can get you nowhere and chasing your own tail...

Regards and thanks for all your help!
Sebastian