Contact Form not showing message

The contact form works, but doesn’t show the message in the received email.
Any help will be appreciated.

<?php
//check if form was sent
if($_POST){
	$to = 'contactform@...com';
	$subject = 'Testing HoneyPot';
	$name = $_POST['name'];
	$email1 = $_POST['email'];
	$message = $_POST['message'];
	//honey pot field
	$honeypot = $_POST['url'];
	//check if the honeypot field is filled out. If not, send mail.
	if( $honeypot > 1 ){
		return;
	}else{
		mail( $to, $name, $email1, $message );
	}
		header('Location: http://www....com/success.html');
		exit;

}
?>

The order of the arguments passed to mail are

$to, $subject , $message [$additional_headers [$additional_parameters

Are you sure you have those right?

Thanks for your help.

I have now tried this:

mail( $to, $subject, $message, $name, $email1 );

and now I receive: to, subject, message, name, but not email.
Any additional help will be welcomed.

The additional headers should be a single string.

Where you have $name should be a variable that contains any additional headers and a proper format.

($to, $subject, $message, $headers)

Where $headers might be “From: myserver@example.com’ . “\r\n” . ‘Reply-To: yourmomma@example.com’ . “\r\n” . 'X-Mailer: PHP/”.

So if you are using $name and $email1 as additional headers, you just need to insert them into a proper email header string.

Thanks for the reply.
I get the $headers); instead of $name, $email1,
but I don’t how I would make a $header: for email1 or name,
Can you please show what that would look like?
Any additional assistance is appreciated.

To send the email name and address in one, they are generally combined in the format:

Dave Green <dgreen@example.com>

so the email address itself is placed between angle brackets, and the two strings placed in the same header field.

Note that if you’re planning on using the form-fillers email address as your “from” address, your mail server might not be happy to send it. You should send the email “from” one of your own addresses, and contain the form information inside the email body, perhaps adding a “reply-to” header with the form-fillers email address in to make it easier to respond.

As can be seen in that post, configuring mail() yourself is a huge PITA, therefore it’s recommended to use a mailing library (SwiftMailer, PHPMailer) that does the hard work.

personally I recommend https://swiftmailer.org/

1 Like

Thanks for the replies. I’m now trying this (below) and receiving all info except ‘name’. Can you help me with getting ‘name’ received from this Form, please?

<?php
//check if form was sent
if($_POST){
	$to = 'contactform@...com';
	$subject = 'Testing HoneyPot';
	$header = '$name';

	$name = $_POST['name'];
	$email = $_POST['email'];
	$message = $_POST['message'];
	//honey pot field
	$honeypot = $_POST['url'];
	//check if the honeypot field is filled out. If not, send mail.
	if( $honeypot > 1 ){
		return;
	}else{
		mail( $to, $subject, $message, $email, $header);
	}
}
?>

You would have to include the name somewhere in the message.

That’s not a valid SMTP header.

Thanks for your reply, but
I don’t understand that.
The person filling in the Contact Form populates the Name field, Email Field and Test Message Area and selects Send.
So the name has to be in the message area?

The email’s message (a.k.a. body), not the form’s.

Thanks for your reply, but I’m not clear on what you’re saying

I’m saying that you have to put the name somewhere in $message.

Thanks again for your reply.
Can you give me an example?

$message .= $name;

Thanks a lot for that. Much appreciated.
I tested that by entering
Chris
in the name field
and
Chris message
in the text body message field area

and it appears in the emailed info to me as:

Chris messageChris

Is there a way to receive the info separated, for example:

Chris Message

Chris

Any additional is welcomed.
Thanks again

Add a newline or two.

If it’s sent as HTML you could have $message .= "<br><br>" . $name;

If it’s plain text, you might have to use newline characters like $message .= "\r\n\r\n" . $name;

Thanks for all the replies and help Greatly appreciated.

Thanks

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.