Axariel Posted December 6, 2008 Share Posted December 6, 2008 I feel really stupid, but I am totally lost when it comes to PHP. I have tried the tutorials, but they lose me fairly quickly. This is the site that I am working on: http://hikariwriting.awardspace.com/characterapp.php What I need for it to do is to send me that form to my e-mail without requiring the user to open their e-mail account? I need another page to load to say that the form was sent successfully. I also need to know how to write an If statement that does not send me an e-mail everytime that the page loads. I am beyond lost and have no idea what to do. Quote Link to comment https://forums.phpfreaks.com/topic/135830-email-form/ Share on other sites More sharing options...
keiran420 Posted December 6, 2008 Share Posted December 6, 2008 Courtasy of W3schools.com <html> <body><?php if (isset($_REQUEST['email'])) //if "email" is filled out, send email { //send email $email = $_REQUEST['email'] ; $subject = $_REQUEST['subject'] ; $message = $_REQUEST['message'] ; mail( "[email protected]", "Subject: $subject", $message, "From: $email" ); echo "Thank you for using our mail form"; } else //if "email" is not filled out, display the form { echo "<form method='post' action='mailform.php'> Email: <input name='email' type='text' /><br /> Subject: <input name='subject' type='text' /><br /> Message:<br /> <textarea name='message' rows='15' cols='40'> </textarea><br /> <input type='submit' /> </form>"; } ?></body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/135830-email-form/#findComment-708019 Share on other sites More sharing options...
Axariel Posted December 6, 2008 Author Share Posted December 6, 2008 It does not seem to be working. I think that I am doing it wrong. Quote Link to comment https://forums.phpfreaks.com/topic/135830-email-form/#findComment-708022 Share on other sites More sharing options...
Axariel Posted December 6, 2008 Author Share Posted December 6, 2008 It says that it is working, but nothing is being sent to my e-mail account. Here is the code: <?php if (isset($_REQUEST['email'])) //if "email" is filled out, send email { //send email $email = $_REQUEST['email'] ; $subject = $_REQUEST['subject'] ; $message = $_REQUEST['message'] ; mail( "[email protected]", "Subject: $subject", $message, "From: $email" ); echo "Your application has been sent! Thank you for applying to the Hikari Writing Workshop 2009!"; } else //if "email" is not filled out, display the form { echo "<form method='post' action='mailform.php'> Email: <input name='email' type='text' /><br /> Subject: <input name='subject' type='text' /><br /> Message:<br /> <textarea name='message' rows='15' cols='40'> </textarea><br /> <input type='submit' /> </form>"; } ?> <form> <table width="600" border="0" cellspacing="0" cellpadding="2"> <tr> <td width="400">Your Name:</td> <td><INPUT NAME="name" TYPE="text" VALUE="" SIZE=20 MAXLENGTH=200></td></tr> <tr><td>Sites That You Play:</td><td><INPUT NAME="sites" TYPE="text" VALUE="" SIZE=20 MAXLENGTH=500></td></tr> <tr><td>Url 1:</td> <td><INPUT NAME="url1" TYPE="text" VALUE="" SIZE=20 MAXLENGTH=200></td></tr> <tr><td>Url 2 or N/A:</td> <td><INPUT NAME="url2" TYPE="text" VALUE="" SIZE=20 MAXLENGTH=200></td></tr> <tr><td>Url 3 or N/A:</td> <td><INPUT NAME="url3" TYPE="text" VALUE="" SIZE=20 MAXLENGTH=200></td></tr> <tr><td>Character Name:</td><td><INPUT NAME="charactername" TYPE="text" VALUE="" SIZE=20 MAXLENGTH=200></td></tr> <tr><td>Character Gender:</td><td><INPUT NAME="charactergender" TYPE="text" VALUE="" SIZE=20 MAXLENGTH=200></td></tr> <tr><td>Character Breed:</td><td><INPUT NAME="characterbreed" TYPE="text" VALUE="" SIZE=20 MAXLENGTH=200></td></tr> <tr><td>Character Color:</td><td><INPUT NAME="charactercolor" TYPE="text" VALUE="" SIZE=20 MAXLENGTH=200></td></tr> <tr><td>Does this character have special abilities/traits?</td><td><INPUT NAME="characterabilities" TYPE="checkbox" VALUE="">Yes</td></tr> <tr><td>If so, what are they?</td><td><INPUT NAME="characterabilities2" TYPE="text" VALUE="" SIZE=60 MAXLENGTH=200></td></tr> <tr><td>Please provide link proof of your character's abilities/traits.</td><td><INPUT NAME="characterabilitiesproof" TYPE="text" VALUE="" SIZE=40 MAXLENGTH=200></td></tr> <tr><td>Does this character have defects?</td><td><INPUT NAME="characterdefects" TYPE="checkbox" VALUE="">Yes</td></tr> <tr><td>If so, what are they?</td><td><INPUT NAME="characterdefects2" TYPE="text" VALUE="" SIZE=60 MAXLENGTH=200></td></tr> <tr><td>Please provide link proof of your character's defects.</td><td><INPUT NAME="characterdefectsproof" TYPE="text" VALUE="" SIZE=40 MAXLENGTH=200></td></tr> <tr><td>What is the best word to describe your character?</td><td><INPUT NAME="characterdescribe" TYPE="text" VALUE="" SIZE=20 MAXLENGTH=200></td></tr> <tr><td>Please provide a link to a post made by your character.</td><td><INPUT NAME="characterpost" TYPE="text" VALUE="" SIZE=20 MAXLENGTH=200></td></tr> <tr><td>How would you rate your writing (Beginner, Intermediate, Intermediate-Advanced, Advanced)?</td><td><INPUT NAME="rate" TYPE="text" VALUE="" SIZE=20 MAXLENGTH=200></td></tr> <tr><td>How long have you been role playing?</td><td><INPUT NAME="years" TYPE="text" VALUE="" SIZE=20 MAXLENGTH=200></td></tr> <tr><td>What is your e-mail address?</td><td><INPUT NAME="email" TYPE="text" VALUE="" SIZE=20 MAXLENGTH=200></td></tr> <tr><td>May we contact you?</td><td><INPUT NAME="contact" TYPE="checkbox" VALUE="">Yes</td></tr> <tr><td>Do you agree with the Hikari copyright rules?</td><td><INPUT NAME="contact" TYPE="checkbox" VALUE="">Yes</td></tr> <br> <tr><td align=center> <INPUT TYPE="submit" value="Submit" style="color: #ffffff; background-color: #000000"> </td></tr></table> </FORM> What am I doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/135830-email-form/#findComment-708029 Share on other sites More sharing options...
glenelkins Posted December 6, 2008 Share Posted December 6, 2008 you also may want to set the 'sendmail' setting. Some servers require this: ini_set ( 'sendmail_from', '[email protected]' ); and i would add this as additional paramaters to the mail() function '[email protected]'; Quote Link to comment https://forums.phpfreaks.com/topic/135830-email-form/#findComment-708032 Share on other sites More sharing options...
Axariel Posted December 6, 2008 Author Share Posted December 6, 2008 Do I replace the mail sending code with your code or add it? And, when the e-mail area of my form isn't filled out, it isn't redirecting to the "invalid" script. Quote Link to comment https://forums.phpfreaks.com/topic/135830-email-form/#findComment-708035 Share on other sites More sharing options...
premiso Posted December 6, 2008 Share Posted December 6, 2008 Yahoo, Hotmail, and especially AOL tend to block php mail from some servers. My dedicated server is on CIHost and AOL blocks mail coming from them, so I do not allow AOL addresses on my site for that reason. I would check with your host, also check your AOL and make sure you add the address the email should be coming from to your trusted list. Quote Link to comment https://forums.phpfreaks.com/topic/135830-email-form/#findComment-708037 Share on other sites More sharing options...
waynew Posted December 6, 2008 Share Posted December 6, 2008 The field names you have and the field names that the script is looking for are different. Quote Link to comment https://forums.phpfreaks.com/topic/135830-email-form/#findComment-708038 Share on other sites More sharing options...
keiran420 Posted December 6, 2008 Share Posted December 6, 2008 its got "action='mailform.php'" in the code i linked, that needs to be the name of the page... Quote Link to comment https://forums.phpfreaks.com/topic/135830-email-form/#findComment-708039 Share on other sites More sharing options...
Axariel Posted December 6, 2008 Author Share Posted December 6, 2008 I made a mailform.php page for this code, but I am kind of confused about everything else. I am really trying to figure all of this out, but it is completely foreign to me. Quote Link to comment https://forums.phpfreaks.com/topic/135830-email-form/#findComment-708043 Share on other sites More sharing options...
Axariel Posted December 6, 2008 Author Share Posted December 6, 2008 I am getting a php error now. Quote Link to comment https://forums.phpfreaks.com/topic/135830-email-form/#findComment-708047 Share on other sites More sharing options...
keiran420 Posted December 6, 2008 Share Posted December 6, 2008 I am getting a php error now. ... which is? People here may be good, but i believe they need more info than "I am getting a php error now."... What is the error? Quote Link to comment https://forums.phpfreaks.com/topic/135830-email-form/#findComment-708054 Share on other sites More sharing options...
glenelkins Posted December 6, 2008 Share Posted December 6, 2008 <?php // Create vars from post foreach ( $_POST as $k = > $v ) { ${$k} = $v; } if ( isset ( $email ) && !empty ( $email ) ) { // Email to & from $mail_to = '[email protected]'; $mail_from = '[email protected]'; // Headers $headers = 'Content-type: text/html\n'; $headers .= 'From: ' . $mail_from . '\n'; // Params $params = '-f' . $mail_from . '\n'; // Ini ini_set ( 'sendmail_from', $mail_from ); // Send if ( !mail ( $mail_to, 'Subject: ' . $subject, $message, $headers, $params ) ) { die ( 'Mail() error' ); } } else { echo '<form method="post" action="mailform.php"> <ul style="list-style: none;"> <li><strong>Email: </strong><input name="email" type="text" /></li> <li><strong>Subject: </strong><input name="subject" type="text" /></li> <li><strong>Message:</strong><br /><textarea name="message" rows="15" cols="40"></textarea></li> <li><input type="submit" /></li> </ul> </form>'; } ?> <form> <table width="600" border="0" cellspacing="0" cellpadding="2"> <tr> <td width="400">Your Name:</td> <td><INPUT NAME="name" TYPE="text" VALUE="" SIZE=20 MAXLENGTH=200></td></tr> <tr><td>Sites That You Play:</td><td><INPUT NAME="sites" TYPE="text" VALUE="" SIZE=20 MAXLENGTH=500></td></tr> <tr><td>Url 1:</td> <td><INPUT NAME="url1" TYPE="text" VALUE="" SIZE=20 MAXLENGTH=200></td></tr> <tr><td>Url 2 or N/A:</td> <td><INPUT NAME="url2" TYPE="text" VALUE="" SIZE=20 MAXLENGTH=200></td></tr> <tr><td>Url 3 or N/A:</td> <td><INPUT NAME="url3" TYPE="text" VALUE="" SIZE=20 MAXLENGTH=200></td></tr> <tr><td>Character Name:</td><td><INPUT NAME="charactername" TYPE="text" VALUE="" SIZE=20 MAXLENGTH=200></td></tr> <tr><td>Character Gender:</td><td><INPUT NAME="charactergender" TYPE="text" VALUE="" SIZE=20 MAXLENGTH=200></td></tr> <tr><td>Character Breed:</td><td><INPUT NAME="characterbreed" TYPE="text" VALUE="" SIZE=20 MAXLENGTH=200></td></tr> <tr><td>Character Color:</td><td><INPUT NAME="charactercolor" TYPE="text" VALUE="" SIZE=20 MAXLENGTH=200></td></tr> <tr><td>Does this character have special abilities/traits?</td><td><INPUT NAME="characterabilities" TYPE="checkbox" VALUE="">Yes</td></tr> <tr><td>If so, what are they?</td><td><INPUT NAME="characterabilities2" TYPE="text" VALUE="" SIZE=60 MAXLENGTH=200></td></tr> <tr><td>Please provide link proof of your character's abilities/traits.</td><td><INPUT NAME="characterabilitiesproof" TYPE="text" VALUE="" SIZE=40 MAXLENGTH=200></td></tr> <tr><td>Does this character have defects?</td><td><INPUT NAME="characterdefects" TYPE="checkbox" VALUE="">Yes</td></tr> <tr><td>If so, what are they?</td><td><INPUT NAME="characterdefects2" TYPE="text" VALUE="" SIZE=60 MAXLENGTH=200></td></tr> <tr><td>Please provide link proof of your character's defects.</td><td><INPUT NAME="characterdefectsproof" TYPE="text" VALUE="" SIZE=40 MAXLENGTH=200></td></tr> <tr><td>What is the best word to describe your character?</td><td><INPUT NAME="characterdescribe" TYPE="text" VALUE="" SIZE=20 MAXLENGTH=200></td></tr> <tr><td>Please provide a link to a post made by your character.</td><td><INPUT NAME="characterpost" TYPE="text" VALUE="" SIZE=20 MAXLENGTH=200></td></tr> <tr><td>How would you rate your writing (Beginner, Intermediate, Intermediate-Advanced, Advanced)?</td><td><INPUT NAME="rate" TYPE="text" VALUE="" SIZE=20 MAXLENGTH=200></td></tr> <tr><td>How long have you been role playing?</td><td><INPUT NAME="years" TYPE="text" VALUE="" SIZE=20 MAXLENGTH=200></td></tr> <tr><td>What is your e-mail address?</td><td><INPUT NAME="email" TYPE="text" VALUE="" SIZE=20 MAXLENGTH=200></td></tr> <tr><td>May we contact you?</td><td><INPUT NAME="contact" TYPE="checkbox" VALUE="">Yes</td></tr> <tr><td>Do you agree with the Hikari copyright rules?</td><td><INPUT NAME="contact" TYPE="checkbox" VALUE="">Yes</td></tr> <br> <tr><td align=center> <INPUT TYPE="submit" value="Submit" style="color: #ffffff; background-color: #000000"> </td></tr></table> </FORM> Quote Link to comment https://forums.phpfreaks.com/topic/135830-email-form/#findComment-708076 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.