Jump to content

PHP Form


thealbinomonkey

Recommended Posts

I have created a PHP form which has the following code:

 

 

<?php
$to      = "[email protected]";
$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);
 
?>
 
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
Link to comment
https://forums.phpfreaks.com/topic/276549-php-form/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/276549-php-form/#findComment-1422987
Share on other sites

Hi Jess, thanks for your help here, I have tried a few solutions relating to those articles, firstly:

 

<?php


$to      = "[email protected]";
$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      = "[email protected]";
$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

Link to comment
https://forums.phpfreaks.com/topic/276549-php-form/#findComment-1422992
Share on other sites

Archived

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

×
×
  • 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.