aeafisme23 Posted January 8, 2008 Share Posted January 8, 2008 I tried searching the forums and did not find too much that i felt would help me. Here is the code that I got from a website that "works" just like it should but when i add into the form a couple more fields it does not do anything. Also i want to add a BCC if possible if not then i need a CC at the least. Thanks so much for taking a look! works: <?php $Subject = "test email"; $toEmail = "[email protected]"; if($submit) { mail($fromEmail, $Subject, $nMessage."\nFrom: ".$fromName."<".$fromEmail.">"); } ?> <html> <head> <title>Mail Tutorial</title> </head> <body bgcolor="#FFFFFF"> <form method="post" action="<?php echo($PHP_SELF) ?>"> Your E-mail: <input type="text" name="fromEmail" size="25"> <br> Your Name: <input type="text" name="fromName" size="25"> <br> Your Message: <br> <textarea cols="50" rows="5" name="nMessage">Your Message Here...</textarea> <br> <input type="submit" value="Submit"> <?php if(submit) { $resultMail = mail($toEmail, $Subject, $nMessage); if($resultMail) { print "Your e-mail has been sent."; } else { print "Your e-mail has not been sent."; } } ?> does not work: <?php $Subject = "test email"; $toEmail = "[email protected]"; if($submit) { mail($fromEmail, $Subject, $fromPhone, $fromAddress, $nMessage."\nFrom: ".$fromName."<".$fromEmail.">"); } ?> <form method="post" action="<?php echo($PHP_SELF) ?>"> <center><table width=\"700\" cellpadding=\"0\" cellspacing=\"0\"> <tbody> <tr> <td><p class="bodyfont">Name*:</p></td> <td><input type="text" name="fromName" size="20" /></td> <td><p class="bodyfont">Phone:</p></td> <td><input type="text" name="fromPhone" size="25" /></td> </tr> <tr> <td><p class="bodyfont">Email*:</p></td> <td><input type="text" name="fromEmail" size="20" /></td> <td><p class="bodyfont">Address:</p></td> <td><input type="text" name="fromAddress" size="30" /></td> </tr> <tr> <td colspan="4"><br><p class="bodyfont">Message*:</p></td> </tr> <tr> <td colspan="4"><p class="bodyfont"><textarea rows="8" name="nMessage" cols="60" class="input"></textarea></p></td> </tr> <tr> <td colspan="4" class="right1"><center><input type="submit" value="Submit" /><input type="reset" value="Reset" /></center><br> <p class="bodyfont">*Required Fields Include (Name, Email, and Message)</p></td> </tr> </tbody> </table></center> </form> Link to comment https://forums.phpfreaks.com/topic/85027-solved-php-e-mail-form-issues/ Share on other sites More sharing options...
revraz Posted January 8, 2008 Share Posted January 8, 2008 http://us3.php.net/manual/en/function.mail.php Link to comment https://forums.phpfreaks.com/topic/85027-solved-php-e-mail-form-issues/#findComment-433606 Share on other sites More sharing options...
aeafisme23 Posted January 8, 2008 Author Share Posted January 8, 2008 What exactly should i be looking for on php.net, i have been there a few times but usually always find sites that are a bit more descriptive helpful. Link to comment https://forums.phpfreaks.com/topic/85027-solved-php-e-mail-form-issues/#findComment-433607 Share on other sites More sharing options...
revraz Posted January 8, 2008 Share Posted January 8, 2008 The parameters that the mail() function takes. Link to comment https://forums.phpfreaks.com/topic/85027-solved-php-e-mail-form-issues/#findComment-433608 Share on other sites More sharing options...
nikefido Posted January 8, 2008 Share Posted January 8, 2008 //use this conditional if(submit) //rather than this one if($submit) It looks like you cut the bottom portion of the sample code off, which was the one doing the work - the top was for testing or something? Anyway, there isn't a variable "$submit" being set anywhere (judging from this code) - but "submit" is... i think... -u can also use this conditional to test also: "if(isset($_POST['submit']))" another problem could be that your form submit button should have "name=submit" also - that allows you to test if "$_POST('submit')" is set (using "isset") Link to comment https://forums.phpfreaks.com/topic/85027-solved-php-e-mail-form-issues/#findComment-433609 Share on other sites More sharing options...
The Little Guy Posted January 8, 2008 Share Posted January 8, 2008 Have a look at this function: mail($fromEmail, $Subject, $fromPhone, $fromAddress, $nMessage."\nFrom: ".$fromName."<".$fromEmail.">"); I don't think you have it correct. it should be: mail($to, $subject, $message, $headers); headers would include things such as: - to - from - cc - Reply-To - etc. Link to comment https://forums.phpfreaks.com/topic/85027-solved-php-e-mail-form-issues/#findComment-433616 Share on other sites More sharing options...
aeafisme23 Posted January 8, 2008 Author Share Posted January 8, 2008 thanks the little guy, i believe your right ill upload and find out! Link to comment https://forums.phpfreaks.com/topic/85027-solved-php-e-mail-form-issues/#findComment-433621 Share on other sites More sharing options...
The Little Guy Posted January 8, 2008 Share Posted January 8, 2008 You may also want to do this: Change: <input type="submit" value="Submit"> To: <input type="submit" name="submit" value="Submit"> and do this: <?php if(isset($_POST['submit'])) { if(mail($to, $subject, $message, $headers)) echo 'Message Sent'; else echo 'Message Failed to send'; } ?> Link to comment https://forums.phpfreaks.com/topic/85027-solved-php-e-mail-form-issues/#findComment-433625 Share on other sites More sharing options...
aeafisme23 Posted January 8, 2008 Author Share Posted January 8, 2008 very helpful again, i take it that i will be declaring variable for header? because you put that will contain the cc, reply-to? Link to comment https://forums.phpfreaks.com/topic/85027-solved-php-e-mail-form-issues/#findComment-433631 Share on other sites More sharing options...
The Little Guy Posted January 8, 2008 Share Posted January 8, 2008 yes, the should look like so: <?php // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= 'To: Mary <[email protected]>, Kelly <[email protected]>' . "\r\n"; $headers .= 'From: Birthday Reminder <[email protected]>' . "\r\n"; $headers .= 'Cc: [email protected]' . "\r\n"; $headers .= 'Bcc: [email protected]' . "\r\n"; ?> Link to comment https://forums.phpfreaks.com/topic/85027-solved-php-e-mail-form-issues/#findComment-433638 Share on other sites More sharing options...
aeafisme23 Posted January 8, 2008 Author Share Posted January 8, 2008 Ok so i ended up following alot of php.net manual and alot of your advice and i would like to repost code, i am getting a few bugs such as the to address is not sending but the bcc is, the subject is not sending either, and i cant post the message even when i declare the names as variables in the form (just posted 1 as an example) (in the email it just says it like the code looks and shows the dollar sign $ followed by fromName .... $fromAddress etc..). Any help would be greatly appreciated! CODE: <?php // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $to = '[email protected]'; $Subject = 'Test: Remind me what again?'; $headers .= 'To: Randy A <[email protected]>, Randy B <rbasdfafxdon.org>' . "\r\n"; $headers .= 'From: The Reminder <[email protected]>' . "\r\n"; //$headers .= 'Cc: [email protected]' . "\r\n"; $headers .= 'Bcc: [email protected]' . "\r\n"; $message = 'You received a message from $fromName their information is $fromPhone, $fromEmail, $fromAddress, and $nMessage'; ?> <form method="post" action="<?php echo($PHP_SELF) ?>"> <center><table width=\"700\" cellpadding=\"0\" cellspacing=\"0\"> <tbody> <tr> <td><p class="bodyfont">Name*:</p></td> <td><input type="text" name="<?php echo $fromName; ?>" size="20" /></td> <td><p class="bodyfont">Phone:</p></td> <td><input type="text" name="fromPhone" size="25" /></td> </tr> <tr> <td><p class="bodyfont">Email*:</p></td> <td><input type="text" name="fromEmail" size="20" /></td> <td><p class="bodyfont">Address:</p></td> <td><input type="text" name="fromAddress" size="30" /></td> </tr> <tr> <td colspan="4"><br><p class="bodyfont">Message*:</p></td> </tr> <tr> <td colspan="4"><p class="bodyfont"><textarea rows="8" name="Message" cols="60" class="input"></textarea></p></td> </tr> <tr> <td colspan="4" class="right1"><center><input type="submit" name="submit" value="Submit"><input type="reset" value="Reset" /></center><br> <p class="bodyfont">*Required Fields Include (Name, Email, and Message)</p></td> </tr> </tbody> </table></center> </form> <?php if(isset($_POST['submit'])) { if(mail($to, $subject, $message, $headers)) echo 'Message Sent Successfully'; else echo 'Message Failed to send, please try again later'; } ?> Link to comment https://forums.phpfreaks.com/topic/85027-solved-php-e-mail-form-issues/#findComment-433684 Share on other sites More sharing options...
revraz Posted January 8, 2008 Share Posted January 8, 2008 In your $message, you need to use Double Quotes around the string if it contains variables. Also, no point on have a TO: in you header, the TO is already set in $to. Link to comment https://forums.phpfreaks.com/topic/85027-solved-php-e-mail-form-issues/#findComment-433689 Share on other sites More sharing options...
aeafisme23 Posted January 8, 2008 Author Share Posted January 8, 2008 any reason why the subject isnt going through, those 2 things you mentioned made those problems go away! Link to comment https://forums.phpfreaks.com/topic/85027-solved-php-e-mail-form-issues/#findComment-433699 Share on other sites More sharing options...
revraz Posted January 8, 2008 Share Posted January 8, 2008 You are using a Capital $Subject and then a lower case $subject. Make them the same. Link to comment https://forums.phpfreaks.com/topic/85027-solved-php-e-mail-form-issues/#findComment-433701 Share on other sites More sharing options...
aeafisme23 Posted January 8, 2008 Author Share Posted January 8, 2008 Thanks rev, it's done!!! woo hoo only 80 posts later a new record hehe. Thanks again everyone Link to comment https://forums.phpfreaks.com/topic/85027-solved-php-e-mail-form-issues/#findComment-433705 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.