Jump to content

Archived

This topic is now archived and is closed to further replies.

Barsoj

Email Contact form CODE // please help

Recommended Posts

Hi everyone.

Pretty desperate, first time that I'm working with php. Learning this language, makes sense, however I can't figure out why my code is not working.

Emails are not coming in at all. Additional required info (phone number, first name, last name) should be included in the message.

Please help. Thank you everyone.

 

<?php
$to          
"abcd@abcd.com";
$subject      "From Website Contact Form";
$first        $_REQUEST['first'];
$last         $_REQUEST['last'];
$email        $_REQUEST['email'];
$phone        $_REQUEST['phone'];
$MESSAGE_BODY "Name: " $_POST["first"] . "\n";
$MESSAGE_BODY "Name: " $_POST["last"] . "\n";
$MESSAGE_BODY "Contact No: " $_POST["phone"] . "\n";
$MESSAGE_BODY "Email: " $_POST["email"] . "\n";
$MESSAGE_BODY "Requirement: " nl2br($_POST["message"]) . "\n";
$message $_REQUEST['message' 'email' 'first' 'last'];
$from    $_REQUEST['email'];
$headers "From:" $from;
mail($to$subject$MESSAGE_BODY$headers);
echo 
"Your message has been sent";
?>

Share this post


Link to post
Share on other sites

strip it down to the basics and test. Can you send a regular email like with:

mail('abcd@abcd.com', 'test email subject', 'test email body', 'FROM: root@your_server.tld');

root@your_server.tld should be your actual domain. If it's not it most likely will be rejected by the receiving server as the domains won't match.

Share this post


Link to post
Share on other sites

One lines 4, 5, 6 and 7 you define variables but never use them?

 

On lines 9 through to 12 you need to use the concatenation assignment operator   .=   not the assignment operator   =   Otherwise only the Requirement line will send in the email body.

 

Line 13. Not sure what you are doing there. 

 

Could you tell use how you are testing this code? Are you sure PHP has been configured to use a mail server? 

Share this post


Link to post
Share on other sites

strip it down to the basics and test. Can you send a regular email like with:

mail('abcd@abcd.com', 'test email subject', 'test email body', 'FROM: root@your_server.tld');

root@your_server.tld should be your actual domain. If it's not it most likely will be rejected by the receiving server as the domains won't match.

Yes, it does work. Thank you.

Share this post


Link to post
Share on other sites

Turn on error reporting and let us know what it has to say. I'm with Ch0cu3r in that I have no clue what you're trying to do with the line '$message $_REQUEST['message' 'email' 'first' 'last'];', but I have to be it's throwing an error that you're not seeing. Put this

error_reporting(-1);
ini_set('display_errors',true);

at the top of your script.

Share this post


Link to post
Share on other sites

Guys, day three learning this language; did the tests and found the mistakes, thanks to you guys for pointing me the right direction.

Thank you Cronix and Ch0cu3r!

 

Here's my final working code:

 

<?php
$to      
"1234@1234.co.uk";
$subject "From Website Contact Form";
$first   $_REQUEST['first'];
$last    $_REQUEST['last'];
$email   $_REQUEST['email'];
$phone   $_REQUEST['phone'];
$MESSAGE_BODY .= "First name: " $_POST["first"] . "\n";
$MESSAGE_BODY .= "Last name: " $_POST["last"] . "\n";
$MESSAGE_BODY .= "Phone No: " $_POST["phone"] . "\n";
$MESSAGE_BODY .= "Email: " $_POST["email"] . "\n\n";
$MESSAGE_BODY .= "Message: " nl2br($_POST["message"]) . "\n";
$from    $_REQUEST['email'];
$headers "From:" $email;
mail($to$subject$MESSAGE_BODY$headers);
echo 
"Your message has been sent";
?>

 

 

Awesome. Thanks again. :happy-04:

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.