kdesilva Posted March 17, 2009 Share Posted March 17, 2009 I have a contact form on my site.... I'm trying to have the user be able to select an interest from a select field which will then email to a certain person, the mail however is not being sent... any help? <?php $EmailTo = "email@server.com"; $Subject = "Web Contact"; $Name = Trim(stripslashes($_POST['Name'])); $Interests = Trim(stripslashes($_POST['Interests'])); $Email = Trim(stripslashes($_POST['Email'])); $Message = Trim(stripslashes($_POST['Message'])); if ($Interests == "General Information") { $EmailTo = "email1@server.com"; } else ($Interests == "Acupuncture") { $EmailTo = "email2@server.com"; } else ($Interests == "Massage Therapy") { $EmailTo = "email3@server.com"; } else ($Interests == "Cranio-Sacral Therapy") { $EmailTo = "email4@server.com"; } // validation $validationOK=true; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; exit; } // prepare email body text $Body = ""; $Body .= "Name: "; $Body .= $Name; $Body .= "\n"; $Body .= "Interests: "; $Body .= $Interests; $Body .= "\n"; $Body .= "Email: "; $Body .= $Email; $Body .= "\n"; $Body .= "Message: "; $Body .= $Message; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$Email>"); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/149817-simple-mail-form-not-sending/ Share on other sites More sharing options...
premiso Posted March 17, 2009 Share Posted March 17, 2009 If on localhost, you have to use a SMTP server. If on a server you should contact your host and ask them. Your code, with a quick glance, seems fine. Quote Link to comment https://forums.phpfreaks.com/topic/149817-simple-mail-form-not-sending/#findComment-786720 Share on other sites More sharing options...
kdesilva Posted March 17, 2009 Author Share Posted March 17, 2009 It is on a server ... what do I need to ask them? Quote Link to comment https://forums.phpfreaks.com/topic/149817-simple-mail-form-not-sending/#findComment-786728 Share on other sites More sharing options...
jlhaslip Posted March 17, 2009 Share Posted March 17, 2009 Ask if the php mail function is available. Quote Link to comment https://forums.phpfreaks.com/topic/149817-simple-mail-form-not-sending/#findComment-786751 Share on other sites More sharing options...
kdesilva Posted March 17, 2009 Author Share Posted March 17, 2009 It's on godaddy servers (not my choice) and I think that's on there Quote Link to comment https://forums.phpfreaks.com/topic/149817-simple-mail-form-not-sending/#findComment-786760 Share on other sites More sharing options...
jen91 Posted March 17, 2009 Share Posted March 17, 2009 that looks ok. can you post the code for the form? Quote Link to comment https://forums.phpfreaks.com/topic/149817-simple-mail-form-not-sending/#findComment-786769 Share on other sites More sharing options...
rvdb86 Posted March 17, 2009 Share Posted March 17, 2009 heres a script i use for sending emails that always works for me <?php //// Email the new password to the person. $Name = ""; //senders name $email = ""; //senders e-mail adress $recipient = ""; //recipient $mail_body = " EMAIL MESSAGE GOES HERE"; $subject = " EMAIL SUBJECT GOES HERE "; //subject $headers = "Content-type: text/html; charset=utf-8\r\n"; $headers .= "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields $headers .= 'MIME-Version: 1.0' . "\r\n"; //$headers .= "Reply-to: <support@click4web.co.il>\r\n"; ini_set('sendmail_from', ' SENDERS EMAIL '); //Suggested by "Some Guy" mail($recipient, $subject, $mail_body, $headers); //mail command hope this helps! Quote Link to comment https://forums.phpfreaks.com/topic/149817-simple-mail-form-not-sending/#findComment-786772 Share on other sites More sharing options...
kdesilva Posted March 17, 2009 Author Share Posted March 17, 2009 Sure, here is the form code: <div id="contact-area"> <form method="post" action="contactengine.php"> <label for="Name" id="Name">Name:</label> <input type="text" name="Name" /> <label for="Interests" id="Interests">Subject:</label> <select id="select1" name="select1"> <option value="em1">General Information</option> <option value="em2">Acupuncture</option> <option value="em3">Massage Therapy</option> <option value="em4">Cranio-Sacral Therapy</option> </select><br /> <label for="Email" id="Email">Email:</label> <input type="text" name="Email" /> <label for="Message" id="Message">Message:</label><br /> <textarea name="Message" rows="20" cols="20"></textarea> <input type="submit" name="submit" value="Submit" class="submit-button" /> </form> <div style="clear: both;"></div> </div> Quote Link to comment https://forums.phpfreaks.com/topic/149817-simple-mail-form-not-sending/#findComment-786773 Share on other sites More sharing options...
kdesilva Posted March 17, 2009 Author Share Posted March 17, 2009 heres a script i use for sending emails that always works for me <?php //// Email the new password to the person. $Name = ""; //senders name $email = ""; //senders e-mail adress $recipient = ""; //recipient $mail_body = " EMAIL MESSAGE GOES HERE"; $subject = " EMAIL SUBJECT GOES HERE "; //subject $headers = "Content-type: text/html; charset=utf-8\r\n"; $headers .= "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields $headers .= 'MIME-Version: 1.0' . "\r\n"; //$headers .= "Reply-to: <support@click4web.co.il>\r\n"; ini_set('sendmail_from', ' SENDERS EMAIL '); //Suggested by "Some Guy" mail($recipient, $subject, $mail_body, $headers); //mail command hope this helps! The only problem is I want to be able to send to different email addresses depending on the option chosen in the select field.. Quote Link to comment https://forums.phpfreaks.com/topic/149817-simple-mail-form-not-sending/#findComment-786775 Share on other sites More sharing options...
jen91 Posted March 17, 2009 Share Posted March 17, 2009 the problem is this line i think <select id="select1" name="select1"> you called it select1 but in the php you are trying to get Interests. try changing to <select id="Interests" name="Interests"> Quote Link to comment https://forums.phpfreaks.com/topic/149817-simple-mail-form-not-sending/#findComment-786777 Share on other sites More sharing options...
kdesilva Posted March 17, 2009 Author Share Posted March 17, 2009 the problem is this line i think <select id="select1" name="select1"> you called it select1 but in the php you are trying to get Interests. try changing to <select id="Interests" name="Interests"> I did see that and I changed it - now it just brings up a blank page and still no emails sent.. Quote Link to comment https://forums.phpfreaks.com/topic/149817-simple-mail-form-not-sending/#findComment-786783 Share on other sites More sharing options...
jen91 Posted March 17, 2009 Share Posted March 17, 2009 change <option value="em1">General Information</option> <option value="em2">Acupuncture</option> <option value="em3">Massage Therapy</option> <option value="em4">Cranio-Sacral Therapy</option> to <option value="General Information">General Information</option> <option value="Acupuncture">Acupuncture</option> <option value="Massage Therapy">Massage Therapy</option> <option value="Cranio-Sacral Therapy">Cranio-Sacral Therapy</option> Quote Link to comment https://forums.phpfreaks.com/topic/149817-simple-mail-form-not-sending/#findComment-786794 Share on other sites More sharing options...
kdesilva Posted March 17, 2009 Author Share Posted March 17, 2009 I think I found the problem - these people have me working on a .net server!!!! I don't even think PHP is installed ... I'm going to try it now in .NET and see if it works, thanks for all the help and I'm really sorry about the confusion.. Quote Link to comment https://forums.phpfreaks.com/topic/149817-simple-mail-form-not-sending/#findComment-786838 Share on other sites More sharing options...
kdesilva Posted March 17, 2009 Author Share Posted March 17, 2009 Actually I think maybe they do support PHP .. this is from their site.. Our Microsoft .NET 3.5 hosting plans (now including Service Pack 1) are ideal for developing dynamic websites and robust applications, and includes database support, PHP 5, ecommerce tools, and more. Quote Link to comment https://forums.phpfreaks.com/topic/149817-simple-mail-form-not-sending/#findComment-786847 Share on other sites More sharing options...
kdesilva Posted March 17, 2009 Author Share Posted March 17, 2009 change <option value="em1">General Information</option> <option value="em2">Acupuncture</option> <option value="em3">Massage Therapy</option> <option value="em4">Cranio-Sacral Therapy</option> to <option value="General Information">General Information</option> <option value="Acupuncture">Acupuncture</option> <option value="Massage Therapy">Massage Therapy</option> <option value="Cranio-Sacral Therapy">Cranio-Sacral Therapy</option> Did that, didn't send any email.. Quote Link to comment https://forums.phpfreaks.com/topic/149817-simple-mail-form-not-sending/#findComment-786848 Share on other sites More sharing options...
jlhaslip Posted March 17, 2009 Share Posted March 17, 2009 I'll ask this one more time: http://www.phpfreaks.com/forums/index.php/topic,243492.msg1137015.html#msg1137015 Is the mail server enabled on the Host? Quote Link to comment https://forums.phpfreaks.com/topic/149817-simple-mail-form-not-sending/#findComment-786854 Share on other sites More sharing options...
kdesilva Posted March 17, 2009 Author Share Posted March 17, 2009 So they say... is there a really simple way to test? Quote Link to comment https://forums.phpfreaks.com/topic/149817-simple-mail-form-not-sending/#findComment-786867 Share on other sites More sharing options...
kdesilva Posted March 17, 2009 Author Share Posted March 17, 2009 They sent me this in terms of sending php email on their server Subject: Sending mail using PHP Article #534 Here is an example script for sending out mail using php: <? // Please specify your Mail Server - Example: mail.yourdomain.com. ini_set("SMTP","mail.YourDomain.com"); // Please specify an SMTP Number 25 and 8889 are valid SMTP Ports. ini_set("smtp_port","25"); // Please specify the return address to use ini_set('sendmail_from', 'ValidEmailAccount@YourDomain.com'); // Set parameters of the email $to = "someone@example.com"; $subject = "Test mail"; $message = "Hello! This is a simple email message."; $from = "someonelse@example.com"; $headers = "From: $from"; // Mail function that sends the email. mail($to,$subject,$message,$headers); ?> Quote Link to comment https://forums.phpfreaks.com/topic/149817-simple-mail-form-not-sending/#findComment-786921 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.