Jump to content

PHP Form


thealbinomonkey

Recommended Posts

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);
 
?>
 
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
Share on other sites

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 by thealbinomonkey
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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