homepage Welcome to WebmasterWorld Guest from 50.19.169.37
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
php sending nightmare!
php contact form doesnt send email
laurasamps




msg:4158697
 7:10 pm on Jun 24, 2010 (gmt 0)

Hi, I am having major problems with my PHP contact form. I have followed everything through the same way as I did with my last website (which worked!) but this time its not having any of it. Ivce even uploaded the new PHP script to my old website hosting and it works (!) my hosting company are being absolutley NO help, i wondered if anyone could take a look and point out th e(probably simple) mistake im making:

<?php
$email = $_POST['email'];
$message = $_POST['message'];
$name = $_POST['name'];
$company = $_POST['company'];
$position = $_POST['position'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$SendEmail ="x@x.com";
$requirements = $_POST['requirements'];

$mailto( "x@x.com", "Feedback Form Results",
"message from x.com:
name $name
company $company
position $position
phone $phone
email $email
'-f'.$SendEmail
requirements $requirements" );
$header( "Location: [x.com...] );

?>

The contact form appears to work to the user - they are redirected to a thank you page, but I am not recieving the email (which is the same as my hosting)

Thanks guys, any advise much appreciated!

Laura

 

Matthew1980




msg:4158723
 7:31 pm on Jun 24, 2010 (gmt 0)

Hi there Laurasamps,

I'm not surprised as it doesn't function, these are the parts that don't function as they aren't declared correctly:-

$email = $_POST['email'];
$message = $_POST['message'];
$name = $_POST['name'];
$company = $_POST['company'];
$position = $_POST['position'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$SendEmail ="x@x.com";
$requirements = $_POST['requirements'];

$mailto( "x@x.com", "Feedback Form Results",
"message from x.com:
name $name
company $company
position $position
phone $phone
email $email
'-f'.$SendEmail
requirements $requirements" );
$header( "Location: [x.com...] );
?>


Apart from there being no error handler, so the client gets redirected even though the email wont go, the email function is called mail(); and not $mailto, your confusing a function with a variable.

When using the mail function, it takes a number of parameters for it to function correctly; Read this detailed description of the mail function from php dot net to see what I mean [uk.php.net ]

Same goes for the header(); function too, it should be header(); and not $header() that is being defined as a function. If you had error reporting turned on, this would have been notified.

Change those two, and I cannot stress enough how much you need to sanitise the data as it is being generated by the user, a little know how and they could inject some dodgy code into the recipients (when it gets there ;)) email client.

Also, you could do with formatting the email a little better - I seem to remember helping on a similar issue a while back.

Hope this helps you a little.

Cheers,
MRb

laurasamps




msg:4158748
 8:02 pm on Jun 24, 2010 (gmt 0)

thanks, ive did as you said, but now its not even redirecting to the thank you page? i have the url right. let me just check:

<?php
$email = $_POST['email'];
$message = $_POST['message'];
$name = $_POST['name'];
$company = $_POST['company'];
$position = $_POST['position'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$SendEmail ="x@x.com";
$requirements = $_POST['requirements'];
'-f'.$SendEmail

mail("x@x.com", "Feedback Form Results",
"message from x.com:
name $name
company $company
position $position
phone $phone
email $email
'-f'.$SendEmail
requirements $requirements" );

header( "Location: [x.com...] );

?>

i will get round to sorting out the security just as soon as i get up working. thank you :)

enigma1




msg:4158759
 8:11 pm on Jun 24, 2010 (gmt 0)

You should take the code as is from the old site that works but before deploying it do a simple test first of all see if the mail is enabled on the server or if the configuration is correct. Use a simple call to the mail function

<?php
mail('test@example.com', 'Test Subject', 'Test Description');
?>

Just put the code in a separate file use a valid email, upload it to the server and see if it works. Do you get an email?

Matthew1980




msg:4158770
 8:23 pm on Jun 24, 2010 (gmt 0)

Hi there laurasamps,

This is by no means secure, but this will at least work, you just need to tweak it for the recipients email address, but from this example you should see where you were going wrong, I have added the mailheaders type of plain text to so that the email client will know what's coming.

Hope this helps you a little bit anyway:-

<?php
$email = $_POST['email'];
$message = $_POST['message'];
$usersname = $_POST['name'];//name is reserved word I think changed to $usersname
$company = $_POST['company'];
$position = $_POST['position'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$SendEmail ="x@x.com";//make sure this address is a vaild email format or it won't go! ;)
$requirements = $_POST['requirements'];

$subject = "Feedback Form Results";

$message = "message from x.com: (".$SendEmail.")\n\r";
$message .= "name ".$usersname."\n\r";
$message .= "Company ".$company."\n\r";
$message .= "Position ".$position."\n\r";
$message .= "Phone ".$phone."\n\r";
$message .= "Email ".$email."\n\r";
$message .= "Requirements ".$requirements."\n\r";

$mailheaders = "content-type: text/plain; charset=UTF-8\r\n";

mail("INSERT THE RECIPIENT EMAIL HERE", $subject, $message, $mailheaders);

header( "Location: YourThanksPage.php");

?>


If the recipient is in the $sendmail var just do this:-

mail($SendEmail, $subject, $message, $mailheaders);

Cheers,
MRb

laurasamps




msg:4158798
 8:49 pm on Jun 24, 2010 (gmt 0)

it still didnt send to my email address! i thought you had it!

someone told me from my hosting company that i need to include:

'-f'.$SendEmail

although i dont know how much i trust them judging by their service. if im allowed to name and shame i will!

i dont know if it means more to you than me?

thank you for your time and expertise!

enigma1




msg:4158800
 8:54 pm on Jun 24, 2010 (gmt 0)

If the simple mail function didn't work the do one final test use another email account or create 2 new emails on your new server and see you can use the simple mail function without problems.

If the mail still doesn't work change hosts.

Matthew1980




msg:4158807
 9:02 pm on Jun 24, 2010 (gmt 0)

HI there laurasamps,

Try this new code on the other server, if it works, this will prove the point that enigma is making, other than that, not sure I need to sleep now :) And with regards to the '-f' Not seen that before, but no doubt that someone on here will know what it means.

Cheers,
MRb

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved