Jump to content

Recommended Posts

Posted

I have my database set up for registrations which is working just fine, now I am working on having at the same time sending the results of the form fields sent by email which is also working but minimally. I have posted my code bit below but need to add more details to it. The email arrives From nobody@..... subject is fine and then I can't get all of the other fields to show and the autoresponder doesn't work at all.

//Check whether the query was successful or not
if($result) {
	mail($myemail, $subject, $fname, $lname, $email, $login);
	header("location: register-success.php");
	exit();
}else {
	die("Query failed");
}
/* Prepare autoresponder subject */
$respond_subject = "Thank you for contacting us!";

/* Prepare autoresponder message */
$respond_message = "Hello!

Thank you for contacting us! We will get back to you
as soon as possible!

Yours sincerely,

Your name
www.yourwebsite.com
";

/* Send the message using mail() function */
mail($email, $respond_subject, $respond_message);

 

In other forms I am using I have a bit of code that lays out the email message very nicely but I get an error 500 whenever I try to add it. Below is a bit of the code so you know what I am talking about. My php is very limited but manage some things trial and error mostly.

$message="$name just filled in your comments form.\n\nTheir phone number is:\n$phone\n\nThey live in:\n$city\n\nThey said:\n$comments\n\nTheir e-mail address is: $email";
				if(mail($to,"Message From MC-HRSolutions.com",$message,"From: $email\n")) {
					echo "Thank you for your enquiry.";
						} else {
								echo "There was a problem sending the mail. Please check that you filled in the form correctly.";

  • 1 month later...
Posted

Hi,

 

If you want to add in a From: header, you can do this:

 


/* Prepare autoresponder subject */
$respond_subject = "Thank you for contacting us!";

/* Prepare autoresponder message */
$respond_message = "Hello!

Thank you for contacting us! We will get back to you
as soon as possible!

Yours sincerely,

Your name
www.yourwebsite.com
";

/* Headers */

$headers = "From: MyName <myAccount@myDomain.com>\r\n";
$headers .= "Reply-To: anotherAccount@myDomain.com\r\n";
// Etc...




/* Send the message using mail() function */
mail($email, $respond_subject, $respond_message, $headers);

 

Looking at this line in your code:

 

mail($myemail, $subject, $fname, $lname, $email, $login);

 

I can't imagine that works does it?

 

You seem to be passing the variables gained from your html form in the mail() function, when what you should be passing is: mail(to, subject, message, headers, extraparameters)

 

What you'll want to do if you're trying to send an email with those variables displayed in it, is just put them in the message body somewhere, eg:

 


/* Example Since I DOn't Know What You're Setting The Variables To */

$myEmail = $_POST['email'];
$subject = 'My Subject';
$message = "Hello,

Here are the details you entered:

First Name: {$fname}
Last Name: {$lname}
Email: {$email}
Login: {$login}";

$headers = "From: MyName <myAccount@myDomain.com>\r\n";
$headers .= "Reply-To: anotherAccount@myDomain.com\r\n"

if($result) {
               mail($myemail, $subject, $message, $headers);
               header("location: register-success.php");
               exit();
       }else {
               die("Query failed");
       }

 

 

 

 

Regarding this bit:

 

$message="$name just filled in your comments form.\n\nTheir phone number is:\n$phone\n\nThey live in:\n$city\n\nThey said:\n$comments\n\nTheir e-mail address is: $email";
                                       if(mail($to,"Message From MC-HRSolutions.com",$message,"From: $email\n")) {
                                               echo "Thank you for your enquiry.";
                                                       } else {
                                                                       echo "There was a problem sending the mail. Please check that you filled in the form correctly.";

 

I tried it on my server and I didn't get any errors, so the error must be in a different section of the code. If you post the whole page of code, I'll see if I can see it.

 

Also, you'll probably want to use the $headers as I outlined above for that section of code.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...