thealbinomonkey Posted April 5, 2013 Share Posted April 5, 2013 I have created a PHP form which has the following code: <?php $to = "example@example.com"; $subject = "Email from Examples.org"; $message = $_REQUEST["message"]; $email = $_REQUEST["email"]; $name = $_REQUEST["name"]; $url = $_REQUEST["url"]; function is_valid_email($email) { return preg_match('#^[a-z0-9.!\#$%&\'*+-/=?^_`{|}~]+@([0-9.]+|([^\s]+\.+[a-z]{2,6}))$#si', $email); } if (!is_valid_email($email)) { echo 'Sorry, invalid email'; exit; } $headers = "From: $email"; mail($to, $subject, $message, $headers, $url); header('Location: http://examples.org/thank-you.html'); ?> But when I receive an email from the form I only get the message in the reply and it does not send me the URL, subject, name or email. Please can someone explain what I am doing wrong. Any help would be greatly received. Thanks Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 5, 2013 Share Posted April 5, 2013 mail http://www.php.net/manual/en/language.types.string.php Quote Link to comment Share on other sites More sharing options...
thealbinomonkey Posted April 5, 2013 Author Share Posted April 5, 2013 Thanks, i'll have a look through those now! Quote Link to comment Share on other sites More sharing options...
thealbinomonkey Posted April 5, 2013 Author Share Posted April 5, 2013 I have one question regarding the answer seen here http://www.php.net/manual/en/function.mail.php if I add the HTML code within message, how do I get it to pull variables from the form? Would it just be "$name" for the name of the user sending the form? Thanks for your help and quick response. Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 5, 2013 Share Posted April 5, 2013 Your message can be a string that has variables in it, yes. Quote Link to comment Share on other sites More sharing options...
thealbinomonkey Posted April 5, 2013 Author Share Posted April 5, 2013 (edited) Hi Jess, thanks for your help here, I have tried a few solutions relating to those articles, firstly: <?php $to = "1@1.com"; $subject = "Email from 1.org"; $message = ' <html> <head> <title>Submission from contact form at 1.org</title> </head> <body> <p>"$name" has just sent the following message</p> <p>"&message" from "&url"</p> </body> </html> '; $headers = "From: $email"; mail($to, $subject, $message, $headers, $url); header('Location: http://1.org/thank-you.html'); ?> and also <?php $to = "1@1.com"; $subject = "Email from 1.org"; $message = $_REQUEST["message\r\nname\r\nurl\r\nemail"]; $email = $_REQUEST["email"]; function is_valid_email($email) { return preg_match('#^[a-z0-9.!\#$%&\'*+-/=?^_`{|}~]+@([0-9.]+|([^\s]+\.+[a-z]{2,6}))$#si', $email); } if (!is_valid_email($email)) { echo 'Sorry, invalid email'; exit; } $headers = "From: $email"; mail($to, $subject, $message, $headers, $url); header('Location: http://1.org/thank-you.html'); ?> And neither of those work, I do not want you to give me the answer I would just like a pointer to let me know if I am going along the right lines? Thanks Edited April 5, 2013 by thealbinomonkey Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 5, 2013 Share Posted April 5, 2013 Jesus Christ. You had all the variables in your first post. Now concatenate them. $email_message = $message."\n".$url etc etc Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.