Jump to content

Recommended Posts

Hi guys am new to php script and need to get the information entered into my form sent to me via email. the froms code is as follows:

 

<form action="Test/sendinfo.php" name="Contact" id="Contact">

              <table width="90%" border="0" cellspacing="2" cellpadding="4">

                <tr>

                  <td width="14%" align="right" valign="top">Name:</td>

                  <td width="86%" colspan="2" valign="top"><input name="name" type="text" id="name" size="30" /></td>

                </tr>

                <tr>

                  <td width="14%" align="right" valign="top">Email:</td>

                  <td colspan="2" valign="top"><input name="email" type="text" id="email" size="30" /></td>

                </tr>

                <tr>

                  <td align="right" valign="top">Tel:</td>

                  <td colspan="2" valign="top"><input name="tel" type="text" id="tel" size="30" /></td>

                </tr>

                <tr>

                  <td width="14%" align="right" valign="top">Subject:</td>

                  <td colspan="2" valign="top"><input name="subject" type="text" id="subject" size="30" /></td>

                </tr>

                <tr>

                  <td valign="top" align="right" width="14%">Message:</td>

                  <td colspan="2" valign="top"><textarea name="message" cols="30" rows="5" id="message"></textarea></td>

                </tr>

                <tr>

                  <td width="14%" align="right"> </td>

                  <td colspan="2"><input name="Submit" type="submit" onclick="MM_validateForm('name','','R','email','','RisEmail','tel','','RisNum','message','','R');return document.MM_returnValue" value="Send" />

                  <input name="Clear" type="reset" id="Clear" value="Clear" /></td>

                </tr>

              </table>

            </form>

 

I did have an attempt after looking at several examples and came up with the following however it doesnt work :-(

 

<?php

$email_to = "...........@.....................co.uk";

$name = $_POST["name"];

$email_from = $_POST["email"];

$message = $_POST["message"];

$email_subject = "Feedback from website";

$headers =

"From: $email_from .\n";

"Reply-To: $email_from .\n";

$message = "Name: ". $name . "\r\nMessage: " . $message;

ini_set("sendmail_from", $email_from);

$sent = mail($email_to, $email_subject, $message, $headers, "-f" .$email_from);

if ($sent)

{

header("Location: http://www..................................co.uk/thankyou.html");

} else {

echo "There has been an error sending your comments. Please try later.";

}

?>

 

i do want to try and get all the info but for my first attempt i just tried to get the name email and message but if any1 can help me get all of it that would be great :-)

Link to comment
https://forums.phpfreaks.com/topic/155716-form-script-help/
Share on other sites

So do you receive the error message ("There has been an error sending your comments. Please try later")?  Or do you get redirected, but receive no email/an incorrect email? Or is there some other problem?

 

Also, in future wrap your code in


tags - it helps us read what you've posted :)

Link to comment
https://forums.phpfreaks.com/topic/155716-form-script-help/#findComment-819640
Share on other sites

$headers =

"From: $email_from .\n";

"Reply-To: $email_from .\n";

 

is wrong and should be:

 

$headers =

"From: $email_from\n".

"Reply-To: $email_from\n";

 

--------------------------------------

 

ini_set("sendmail_from", $email_from);

 

why set the from twice?

 

--------------------------------------

 

i would really encourage adding some anti-spam method and some validation on everything what you get from $_POST

 

--------------------------------------

 

P.S. use ' (single quote) instead of " (double quote) only use double if you need to parse something in the string like:

 

$headers =

"From: $email_from\n".

"Reply-To: $email_from\n";

 

otherwise use ' (single quote)

Link to comment
https://forums.phpfreaks.com/topic/155716-form-script-help/#findComment-819641
Share on other sites

<?php
$email_to = "...........@.....................co.uk";
$name = $_POST["name"];
$email_from = $_POST["email"];
$message = $_POST["message"];
$email_subject = "Feedback from website";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $email_from \r\n";
$message = "Name: ". $name . "\r\nMessage: " . $message;

// ini_set("sendmail_from", $email_from); // not sure if this is needed, but I do not think so (unless your host says different).
$sent = mail($email_to, $email_subject, $message, $headers, "-f" .$email_from);

if ($sent) {
header("Location: http://www..................................co.uk/thankyou.html");
}else {
echo "There has been an error sending your comments. Please try later.";
}
?>

 

For the headers (if on linux) you need to use \r\n Give that a try and see what comes of it. Also, the email being sent to may be the issue, as Yahoo, Hotmail and AOL block most mail coming from php servers if the server ip does not have a mail MX record, so that could be your problem.

Link to comment
https://forums.phpfreaks.com/topic/155716-form-script-help/#findComment-819651
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.