jacko310592 Posted November 22, 2009 Share Posted November 22, 2009 hey guys, im having a little trouble here, i need a contact form but i do not have acess to the php.ini file with my web host, i heard of a way to configure the mail from (etc) with a header (or somthing), but i dont know how to do it. my code so far is as follows: HTML: <form method="POST" action="contact.php"> <input type="text" name="name"> <br/> <input type="text" name="email"> <br/> <textarea rows="9" name="message" cols="30"></textarea> <br/> <input type="submit" value="Submit" name="submit"> </form> PHP: <?php if(isset($_POST['submit'])) { $to = "[email protected]"; $subject = "Contact from Site"; $name_field = $_POST['name']; $email_field = $_POST['email']; $message = $_POST['message']; $body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message"; echo "Data has been submitted to $to!"; mail($to, $subject, $body); } else { echo "an error has occurred"; } ?> can anyone please help thanks guys Link to comment https://forums.phpfreaks.com/topic/182509-contact-form-wthout-phpini/ Share on other sites More sharing options...
jacko310592 Posted November 22, 2009 Author Share Posted November 22, 2009 the following is what i recieve at the moment if i try to use the script Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing it is the "custom "From:" header missing" part which i am interested in, i just cant find anything on the web thats helping with it Link to comment https://forums.phpfreaks.com/topic/182509-contact-form-wthout-phpini/#findComment-963325 Share on other sites More sharing options...
Cardale Posted November 22, 2009 Share Posted November 22, 2009 $headers = "From: [email protected]\r\n"; $headers .= "Reply-To: [email protected]\r\n"; $headers .= "Return-Path: [email protected]\r\n"; $headers .= "CC: [email protected]\r\n"; $headers .= "BCC: [email protected]\r\n"; mail($to, $subject, $body, $headers) http://php.net/manual/en/function.mail.php Should be something like this.... Link to comment https://forums.phpfreaks.com/topic/182509-contact-form-wthout-phpini/#findComment-963328 Share on other sites More sharing options...
jacko310592 Posted November 22, 2009 Author Share Posted November 22, 2009 thanks for the reply Cardale, i added your code to the top of my php section, (which i am asuming that is where it needed to be added) but i continue to recieve the same error. any ideas? Link to comment https://forums.phpfreaks.com/topic/182509-contact-form-wthout-phpini/#findComment-963331 Share on other sites More sharing options...
Cardale Posted November 22, 2009 Share Posted November 22, 2009 $headers = "From: [email protected]\r\n"; $headers .= "Reply-To: [email protected]\r\n"; $headers .= "Return-Path: [email protected]\r\n"; $headers .= "CC: [email protected]\r\n"; $headers .= "BCC: [email protected]\r\n"; $headers .= "X-Mailer: PHP/" . phpversion(); mail($to, $subject, $body, $headers) Try adding the addition header I updated the code up top. I assume your using a hosting service? Also try this. ini_set ("SMTP","mail.website.com"); ini_set ("sendmail_from","[email protected]"); Link to comment https://forums.phpfreaks.com/topic/182509-contact-form-wthout-phpini/#findComment-963338 Share on other sites More sharing options...
jacko310592 Posted November 22, 2009 Author Share Posted November 22, 2009 i now get this message: Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() as i have no access to the php.ini, i need to use a function called "ini_set()" according to the error i got, any ideas how this is done? thanks once again Link to comment https://forums.phpfreaks.com/topic/182509-contact-form-wthout-phpini/#findComment-963344 Share on other sites More sharing options...
jacko310592 Posted November 22, 2009 Author Share Posted November 22, 2009 would this be correct to send through google mail? ini_set ("SMTP","smtp.gmail.com"); ini_set ("sendmail_from","[email protected]"); Link to comment https://forums.phpfreaks.com/topic/182509-contact-form-wthout-phpini/#findComment-963348 Share on other sites More sharing options...
Cardale Posted November 22, 2009 Share Posted November 22, 2009 I would assume so, but I have never tried personally. Try reading this http://digiex.net/networking/544-configuring-php-under-windows-use-gmail-external-smtp-server-ssl.html Link to comment https://forums.phpfreaks.com/topic/182509-contact-form-wthout-phpini/#findComment-963354 Share on other sites More sharing options...
jacko310592 Posted November 22, 2009 Author Share Posted November 22, 2009 i now get the following error Warning: mail() [function.mail]: SMTP server response: 530 5.7.0 Must issue a STARTTLS command first. 15sm1297204ewy.0 and unfortunatly, my web host wont let me edit or use any .ini files like that tutorial link you just sent me shows, but thanks for trying to help (Y) Link to comment https://forums.phpfreaks.com/topic/182509-contact-form-wthout-phpini/#findComment-963357 Share on other sites More sharing options...
Cardale Posted November 22, 2009 Share Posted November 22, 2009 darn sorry. I don't have much experience with your situation. What host are you using if you don't mind me asking? Sounds like an odd setup. Link to comment https://forums.phpfreaks.com/topic/182509-contact-form-wthout-phpini/#findComment-963422 Share on other sites More sharing options...
jacko310592 Posted November 22, 2009 Author Share Posted November 22, 2009 hosting.eu.pn its a free host, cant afford to get paid hosting yet, but with many free hosting sites they dont let you mess with the .ini file :/ well, thats what im lead to believe anyway Link to comment https://forums.phpfreaks.com/topic/182509-contact-form-wthout-phpini/#findComment-963485 Share on other sites More sharing options...
cags Posted November 22, 2009 Share Posted November 22, 2009 You can't use the mail function to send e-mails via gmails' SMTP server. They require authentication and the mail function doesn't support it. Link to comment https://forums.phpfreaks.com/topic/182509-contact-form-wthout-phpini/#findComment-963509 Share on other sites More sharing options...
jacko310592 Posted November 22, 2009 Author Share Posted November 22, 2009 oh, what about Yahoo Mail etc? Link to comment https://forums.phpfreaks.com/topic/182509-contact-form-wthout-phpini/#findComment-963519 Share on other sites More sharing options...
cags Posted November 22, 2009 Share Posted November 22, 2009 I believe that also requires authentication, but I could be wrong. Link to comment https://forums.phpfreaks.com/topic/182509-contact-form-wthout-phpini/#findComment-963529 Share on other sites More sharing options...
jacko310592 Posted November 22, 2009 Author Share Posted November 22, 2009 hmm, can you think of anyway sending a message on my site will be posible then? (remembering that i dont have access to php.ini, or the use of .ini files [as far as i know]) thanks Link to comment https://forums.phpfreaks.com/topic/182509-contact-form-wthout-phpini/#findComment-963532 Share on other sites More sharing options...
cags Posted November 22, 2009 Share Posted November 22, 2009 Provide ini_set allows you to change the values, which it appears to you just need to find an SMTP server that you can use that doesn't require authentication. For testing purposes I used to use the one provided by my ISP. Link to comment https://forums.phpfreaks.com/topic/182509-contact-form-wthout-phpini/#findComment-963536 Share on other sites More sharing options...
jacko310592 Posted November 22, 2009 Author Share Posted November 22, 2009 okay thank you, this is my code so far, could you confirm for me whether it will work properly (once ive found an SMTP server that doesn't require authentication) <?php $headers = "From: [email protected]\r\n"; $headers .= "Reply-To: [email protected]\r\n"; $headers .= "Return-Path: [email protected]\r\n"; $headers .= "X-Mailer: PHP/" . phpversion(); ini_set ("SMTP","smtp.provider.com"); ini_set ("sendmail_from","[email protected]"); if(isset($_POST['submit'])) { $to = "[email protected]"; $subject = "Contact from Site"; $name_field = $_POST['name']; $email_field = $_POST['email']; $message = $_POST['message']; $body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message"; echo "Data has been submitted to $to!"; mail($to, $subject, $body, $headers);} else {echo "an error has occurred";} ?> at the moment i dont understand how the code will access the email its going to use to send the messages, is there some code im missing at the moment for the email user name and password? Link to comment https://forums.phpfreaks.com/topic/182509-contact-form-wthout-phpini/#findComment-963545 Share on other sites More sharing options...
cags Posted November 22, 2009 Share Posted November 22, 2009 Hard to say for certain, but it looks about right. Link to comment https://forums.phpfreaks.com/topic/182509-contact-form-wthout-phpini/#findComment-963546 Share on other sites More sharing options...
jacko310592 Posted November 22, 2009 Author Share Posted November 22, 2009 thanks (: now just gotta find the SMTP server without authentication, im guessing thats not going to be easy =/ Link to comment https://forums.phpfreaks.com/topic/182509-contact-form-wthout-phpini/#findComment-963549 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.