Trouble Setting up a webform to send a PHP email

Connect with other users about what to run on your webhosting (and how to run it) here.
Post Reply
AustinNotAustin
New to forums
New to forums
Posts: 4
https://www.youtube.com/channel/UC40BgXanDqOYoVCYFDSTfHA
Joined: Fri Jul 09, 2021 10:40 am

Trouble Setting up a webform to send a PHP email

Post by AustinNotAustin »

Hey,

I'm creating a webform that users can fill out and hit send. This form will then send me an email with their information.

I'm new to PHP and simply followed tutorials to get here.

I think I have everything set up properly, but when I access the PHP successfully, no email is received in my NFO email.

Here's the small code snippet I used:

Code: Select all

<?php
if (isset($_POST['submit'])) {
    $name = $_POST['name'];
    $emailFrom = $_POST['email'];
    $message = $_POST['message'];

    $emailTo = "<redacted for user's privacy>";
    $subject = "Interactive Resume Message";
    $headers = "From: ".$emailFrom;
    $text = "New message from: ".$name."\n\n".$message."\n\nContact Email: ".$emailFrom;

    mail($emailTo, $subject, $text, $headers);
    header("Location: index.php?mailsent");
}

?>
Thoughts anyone?

Thanks,
-Austin
Last edited by hiimcody1 on Fri Jul 09, 2021 12:16 pm, edited 1 time in total.
Reason: Removed their email from it
AustinNotAustin
New to forums
New to forums
Posts: 4
Joined: Fri Jul 09, 2021 10:40 am

Re: Trouble Setting up a webform to send a PHP email

Post by AustinNotAustin »

SOLUTION:

The

Code: Select all

if (isset($_POST['submit'])) {
was my problem. I was never actually sending a submit value in my array from the HTML. Thus, this if statement was never actually called. (I think)

I checked my array for all the fields it had with:

Code: Select all

echo "<pre>";

    print_r($_POST);

    $name = $_POST['name'];
    $emailFrom = $_POST['email'];
    $message = $_POST['message'];

echo "</pre>";
Then just changed the first if statement to

Code: Select all

if (isset($_POST)) {
and was golden.
Post Reply