Forum Moderators: coopster
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
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].
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
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.
...Some SMTP won't accept e-mail with the "From: host@domain" without the suffix "com", like "domain.com"...
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
Glad you resolved the issue, Sastian!
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