- This topic is empty.
-
AuthorPosts
-
July 27, 2015 at 6:55 pm #205655
mrcodes
ParticipantHey guys, I started learning php and creating an email form. But I keep getting an error on my “if ((mail)” statement. What am I doing wrong? And are there any other errors I’m not seeing?
Thanks.
<?php $name = $_POST['name']; $email = $_POST['email']; $tel = $_POST['tel']; $message = $_POST['message']; $from = 'From: User'; $to = '[email protected]'; $subject = 'Hello'; $human = $_POST['human']; $body = "From: $name\n E-Mail: $email\n Message:\n $message Retired: $retired\n Veteran: $vet \n Family: $family \n dd: $dd \n " ; if ($_POST['submit'] { if (mail($to, $subject, $body, $from, $tel)) { echo '<p>Your message has been sent!</p>'; } else { echo '<p>Something went wrong, go back and try again!</p>'; } ?>
July 28, 2015 at 6:28 am #205667drose379
ParticipantPeople will be able to give you better help if you provide error PHP is giving you. It looks like you are missing a closing bracket
}
for your first if statement.July 28, 2015 at 6:31 am #205668drose379
ParticipantAlso, missing a closing
)
aroundif($_POST["submit"])
July 28, 2015 at 6:39 am #205669drose379
ParticipantAlso, what are you trying to do with
if($_POST["submit"])
. Seems like your trying to check if the submit button is clicked? For that, you would want to use theisset()
function.August 4, 2015 at 5:21 pm #206080mrcodes
ParticipantHello drose379,
Thanks a lot. I literally starting learning php last week. I added the changes, but I am still getting errors. The closing bracket on if “(mail())” and “else {” says “syntax error”. That’s it.
if ($_POST['submit']) { if (mail($to, $subject, $body, $from, $tel)) } { echo '<p>Your message has been sent!</p>'; } else { echo '<p>Something went wrong, go back and try again!</p>'; }
August 4, 2015 at 6:28 pm #206081drose379
ParticipantSure, you are getting this error because your code has syntax issues. Heres what it should look like
if ($_POST["submit"]) { if (mail($x,$y,$z,$foo,$bar)) { echo "Your message was sent"; } } else { echo "Something went wrong"; }
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.