php mail form not working

php mail form not working

Posted by: kidart
Posted on: 2009-10-19 09:29:00

Iīm having problems with my contact form. It works perfect in every other server i try it, but when i upload it to dreamhost i donīt recieve any e-mail.

this is the php code:

<?
//!empty($HTTP_POST_VARS['sender_mail']) || !empty($HTTP_POST_VARS['sender_message']) || !empty($HTTP_POST_VARS['sender_subject']) || !empty($HTTP_POST_VARS['sender_name'])
if(1)
{
$to = 'pablo@kidart.com.ar';
$subject = "Irene Brandt Webmail";
$body = stripslashes($HTTP_POST_VARS['sender_messag']);
$body .= "\n\nThe following person has subscribed to your maillist \n";
$body .= "name: " . $HTTP_POST_VARS['sender_name'] . ", email: " . $HTTP_POST_VARS['sender_mail'] . ", country: " . $HTTP_POST_VARS['sender_subject'] . ", profession: ". $HTTP_POST_VARS['sender_message'] ."\n";
$header = "From: " . $HTTP_POST_VARS['sender_name'] . " <" . $HTTP_POST_VARS['sender_mail'] . ">\n";
$header .= "Reply-To: " . $HTTP_POST_VARS['sender_name'] . " <" . $HTTP_POST_VARS['sender_mail'] . ">\n";
$header .= "X-Mailer: PHP/" . phpversion() . "\n";
$header .= "X-Priority: 1";
if(mail($to, $subject, $body, $header))
{
echo "output=sent";
} else {
echo "output=error";
}
} else {
echo "output=error";
}

?>




do i have to edit the php.ini to enable the php mail () function??

I would really apreciate to have a little help with this, itīs the last thing to solve before launching the site.

Re: php mail form not working

Posted by: sXi
Posted on: 2009-10-19 09:40:00

Didn't read the code (and am off to bed!) but noticed in the feed that you're using short tags.


<?php

echo "Need some sleep!";

?>





How To Install PHP.INI / ionCube on DreamHost

Re: php mail form not working

Posted by: davidmintz
Posted on: 2009-10-19 10:02:00

I am having the same problem. Since DH moved me from one server to another, mail() returns false and I am not amused.

Short tags should not make any difference.

Re: php mail form not working

Posted by: kidart
Posted on: 2009-10-19 10:13:00

so itīs impossible to make any contact form work???

iīm doing this site in flash, is there any other way to have a mail form???

the url is: http://www.irenebrandt.com/new/irenebrandt_white.html
the form is in the "contact" section...

Re: php mail form not working

Posted by: davidmintz
Posted on: 2009-10-19 10:22:00

I don't know your specific environment or the nature of your error, but in my case, I had a custom php.ini which had no setting for sendmail_path. I set it to

sendmail_path = "/usr/sbin/sendmail -t -i"

that is, same as /etc/php5/cgi/php.ini, and it's working.

I imagine others will run into this issue following the server switch, so let me repeat that again loudly:

if you have a custom php.ini, you need to have sendmail_path = "/usr/sbin/sendmail -t -i"

Re: php mail form not working

Posted by: davidmintz
Posted on: 2009-10-19 10:24:00

Another thing, I see you are using the $HTTP_POST_VARS array and that is long deprecated -- unsupported even -- in modern PHP. Use $_POST instead.

Re: php mail form not working

Posted by: kidart
Posted on: 2009-10-19 10:31:00

thank you very much.
iīll try fixing it that way.
can you tell me how to edit php.ini?

iīve to find the "sendmail" line in that file, and replace it with the one you told me?

Re: php mail form not working

Posted by: kidart
Posted on: 2009-10-19 11:27:00

ok. iīve already edit the phpini , and replace the sendmail_path: nothing changed. the form canīt send any email...

any other tip or idea?


Re: php mail form not working

Posted by: erikjacobsen
Posted on: 2009-10-19 13:04:00

How is your code looking now?

Re: php mail form not working

Posted by: kidart
Posted on: 2009-10-19 21:29:00

my code look like this:


<?
//!empty($HTTP_POST_VARS['sender_mail']) || !empty($HTTP_POST_VARS['sender_message']) || !empty($HTTP_POST_VARS['sender_subject']) || !empty($HTTP_POST_VARS['sender_name'])
if(1)
{
$to = 'mymail@kidart.com.ar';
$subject = "Irene Brandt Webmail";
$body = stripslashes($_POST['sender_messag']);
$body .= "\n\nThe following person has subscribed to your maillist \n";
$body .= "name: " . $_POST['sender_name'] . ", email: " . $_POST['sender_mail'] . ", country: " . $_POST['sender_subject'] . ", profession: ". $_POST['sender_message'] ."\n";
$header = "From: " . $_POST['sender_name'] . " <" . $_POST['sender_mail'] . ">\n";
$header .= "Reply-To: " . $_POST['sender_name'] . " <" . $_POST['sender_mail'] . ">\n";
$header .= "X-Mailer: PHP/" . phpversion() . "\n";
$header .= "X-Priority: 1";
if(mail($to, $subject, $body, $header))
{
echo "output=sent";
} else {
echo "output=error";
}
} else {
echo "output=error";
}

?>


The curious thing is that iīve tried every single flash contact form script i found on the internet: everyone works perfect when i use it in my old server but when i upload the same files to dreamhost, without changin anything... it doesnt work.
I donīt know what to do... the only answer seems to be changing my hosting service??

Re: php mail form not working

Posted by: sXi
Posted on: 2009-10-19 22:06:00

In reply to:

Short tags should not make any difference.


They will if short_open_tag is OFF (which is the default when one sets up PHP).

In reply to:

ok. iīve already edit the phpini , and replace the sendmail_path: nothing changed. the form canīt send any email...


sendmail is already in the path, no need to edit it unless the php build is trash.

In reply to:

any other tip or idea?


Check out Atropos7's post from last week in which he included a nice piece of code that tests conditions.

The part down the bottom after ($_SERVER['REQUEST_METHOD'] === 'POST') shows how to format the send correctly.




How To Install PHP.INI / ionCube on DreamHost

Re: php mail form not working

Posted by: erikjacobsen
Posted on: 2009-10-20 00:58:00

Headers must be separated with "\r\n" not "\n" - that's what the standard says.

Re: php mail form not working

Posted by: davidmintz
Posted on: 2009-10-20 11:59:00

If short tags are enabled, the script will be parsed and the style of the tag has no bearing on mail() -- that's my point

As for sendmail_path, my experience suggests that if this directive is not found by PHP, it falls back on a default which does not work on certain DH servers, and mail() returns false.

Re: php mail form not working

Posted by: sXi
Posted on: 2009-10-20 12:23:00

If you install PHP following a Wiki script open_short_tags won't be enabled. Which was my point wink




How To Install PHP.INI / ionCube on DreamHost

cool its working thanks

Posted by: yogasupplies1
Posted on: 2009-10-23 23:20:00

cool its working thanks

(link spam removed, user banned)
Edited by rlparker on 10/24/09 10:50 AM (server time).

Tags: mail formphp codee mail