Jump to content

Archived

This topic is now archived and is closed to further replies.

perezf

How to stop an email from being sent "Required Fields"

Recommended Posts

i made this code to send an email but i dont want anything sent if the user doesnt fill in required fields


[code]<?php
$from_header = "From: ".$_POST['from'];
$name = $_POST['name'];
$to = "2fr3sh@gmail.com";
$heading = "2fr3sh Email";
$contents = $_POST['message'];

if(isset($from_header)) && if(isset($contents)) {
mail($to, $heading, $contents, $from_header);
} else {header("Location: contact.html");}
?>[/code]

Share this post


Link to post
Share on other sites
you can use "empty" or "strlen" functions to avoid sending blank forms. like this:

[code]if(empty($name)){
  echo "please fill in the name";
  exit();
}
// continue here[/code]

Share this post


Link to post
Share on other sites
i want to try and stick to the issets and im getting the following code error
[quote]Parse error: parse error, unexpected T_BOOLEAN_AND in /hsphere/local/home/way2fr3s/2fr3sh.com/new/sendmail.php on line 24[/quote]
[code]<?php
$from_header = "From: ".$_POST['from'];
$name = $_POST['name'];
$to = "2fr3sh@gmail.com";
$heading = "2fr3sh Email";
$contents = $_POST['message'];

if(isset($from_header)) && if(isset($contents)) {
mail($to, $heading, $contents, $from_header);
} else {header("Location: contact.html");}
?>[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.