Nisaa Roberts Nisaa Roberts - 2 months ago 9
PHP Question

Send contents of contact form direct to email via php

I have a contact form on my wordpress site but I cannot get information from the form to send to my email address when the submit button is clicked.

Once the submit button has been clicked and the email has been sent I would like a confirmation to appear underneath the submit button that the message has been sent/error if it hasn't. Note: I will update the css for the contact form to accommodate the extra text.

This is my form code:

<form action="secure_email.php" method="post" id="contact-form-content">
<h5>You have had a look, so let's get cracking. Email me at or use this nifty thing.</h5><br></br>
<legend>Contact Form</legend>
<input type="text" placeholder="Full Name" name="full-name" id="full-name" required;><br></br>
<input type="text" placeholder="Email" name="email" id="email" required;><br></br>
<textarea placeholder="Message" name="message" id="message" rows="100" cols="100" wrap="hard" required;></textarea><br></br>
<button type="submit" name="submit" value="submit">Send</button>

And this is secure_email.php file:

$to = ""; // this is your Email address
$email = $_POST['email']; // this is the sender's Email address
$full-name = $_POST['full-name'];
$subject = "Form submission";
$message = $full-name . " " . $email . " wrote the following:" . "\n\n" . $_POST['message'];

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to, $subject, $message, $headers);

if (isset($_POST['submit']))
if (mail($to, $subject, $message, $headers))

echo "Thank you for contacting me!";
echo '<p>Something went wrong, go back and try again!</p>';


Please use mail functions.

PHP Mail Function

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to, $subject, $message, $headers);

WordPress Mail Function

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