jbingman Posted July 2, 2008 Share Posted July 2, 2008 <?php $link = "<a href='/contact.php'>Click here to go back</a>"; if(!$name || !$email || !$comments) { echo "<font color='red'>Please fill in all fields</font><br />"; echo "<form action='action.php' method='post' name='contactform'> <table height='194' bgcolor='#333333'> <tr> <td width='240' height='521'><font color='red'>*</font>Full Name:<br /> <input type='text' name='name' /><br /></td> <td width='328'><font size='1'><font color='red'>*</font> Indicates Required Fields</font></td> </tr> <tr> <td height='52' colspan='2'><font color='red'>*</font>E-mail Address:<br /> <input type='text' name='email' /><br /></td> </tr> <tr> <td colspan='2'>Phone Number:<br /> <input type='text' maxlength='3' size='4' name='areacode'/>-<input type='text' maxlength='3' size='4' name='3digits' />-<input type='text' maxlength='4' size='6' name='4digits' /><br /></td> </tr> <tr> <td colspan='2'><font color='red'>*</font>Subject:<br /> <input type='text' name='subject'/><br /></td> </tr> <tr> <td colspan='2'><font color='red'>*</font>Questions/Comments:<br /> <textarea cols='50' rows='10' name='comments'>Comment here</textarea></td> </tr> <tr> <td colspan='2'><br /> <input type='reset' value='Reset Form' /> <input type='submit' value='Submit Form' name='submit' /></td> </tr> </table> </form>"; exit; } if(!eregi('^[a-z0-9_]+@[a-z0-9\-]+\.[a-z0-9\-\.]+$', $email)) { echo "<font color='red'>E-mail is not a valid address</font><br />"; echo "<form action='action.php' method='post' name='contactform'> <table height='194' bgcolor='#333333'> <tr> <td width='240' height='52'><font color='red'>*</font>Full Name:<br /> <input type='text' name='name' /><br /></td> <td width='328'><font size='1'><font color='red'>*</font> Indicates Required Fields</font></td> </tr> <tr> <td height='52' colspan='2'><font color='red'>*</font>E-mail Address:<br /> <input type='text' name='email' /><br /></td> </tr> <tr> <td colspan='2'>Phone Number:<br /> <input type='text' maxlength='3' size='4' name='areacode'/>-<input type='text' maxlength='3' size='4' name='3digits' />-<input type='text' maxlength='4' size='6' name='4digits' /><br /></td> </tr> <tr> <td colspan='2'><font color='red'>*</font>Subject:<br /> <input type='text' name='subject'/><br /></td> </tr> <tr> <td colspan='2'><font color='red'>*</font>Questions/Comments:<br /> <textarea cols='50' rows='10' name='comments'>Comment here</textarea></td> </tr> <tr> <td colspan='2'><br /> <input type='reset' value='Reset Form' /> <input type='submit' value='Submit Form' name='submit' /></td> </tr> </table> </form>"; exit; }else{ $name = trim(stripslashes($_REQUEST['name'])); $email = trim($_REQUEST['email']); $phone = $_REQUEST['areacode' . '3digit' . '4digit']; $subject = $_REQUEST['subject']; $comments = stripslashes($_REQUEST['comments']); mail('[email protected]', $subject, $comments, $phone, 'From:$name <$email>'); echo "<br />"; echo "<p>Thank you for your comments.<br />"; echo "<a href='contact.php'>click here to continue.</a></p>"; } ?> Here's my script i have for a comment/contact section on my page that isnt working. it wont pass the first if even if i fill in all the fields. its probably something stupid but i dont know PHP inside and out. Link to comment https://forums.phpfreaks.com/topic/112920-solved-php-mail-script/ Share on other sites More sharing options...
DarkWater Posted July 2, 2008 Share Posted July 2, 2008 You don't initialize the variables until you get to the else { }, so obviously they're not set when you first try to use them. Set them at the top. Also, don't use $_REQUEST. Use the appropriate superglobal (i.e: $_POST, $_GET, etc). Link to comment https://forums.phpfreaks.com/topic/112920-solved-php-mail-script/#findComment-580037 Share on other sites More sharing options...
jbingman Posted July 3, 2008 Author Share Posted July 3, 2008 ok i got that to work but now its just not sending any email to the email address. and is there a way to add 2 emails for the contact info to be sent to? Link to comment https://forums.phpfreaks.com/topic/112920-solved-php-mail-script/#findComment-581242 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.