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 = "me@me.com"; $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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Cardale Posted November 22, 2009 Share Posted November 22, 2009 $headers = "From: myemail@email.com\r\n"; $headers .= "Reply-To: myemail@email.com\r\n"; $headers .= "Return-Path: myemail@email.com\r\n"; $headers .= "CC: myemail@email.com\r\n"; $headers .= "BCC: myemail@email.com\r\n"; mail($to, $subject, $body, $headers) http://php.net/manual/en/function.mail.php Should be something like this.... Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
Cardale Posted November 22, 2009 Share Posted November 22, 2009 $headers = "From: myemail@email.com\r\n"; $headers .= "Reply-To: myemail@email.com\r\n"; $headers .= "Return-Path: myemail@email.com\r\n"; $headers .= "CC: myemail@email.com\r\n"; $headers .= "BCC: myemail@email.com\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","webmaster@website.com"); Quote Link to comment 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 Quote Link to comment 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","myaddress@googlemail.com"); Quote Link to comment 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 Quote Link to comment 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) Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
jacko310592 Posted November 22, 2009 Author Share Posted November 22, 2009 oh, what about Yahoo Mail etc? Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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@email.com\r\n"; $headers .= "Reply-To: email@email.com\r\n"; $headers .= "Return-Path: email@email.com\r\n"; $headers .= "X-Mailer: PHP/" . phpversion(); ini_set ("SMTP","smtp.provider.com"); ini_set ("sendmail_from","email@email.com"); if(isset($_POST['submit'])) { $to = "me@me.com"; $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? Quote Link to comment 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. Quote Link to comment 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 =/ Quote Link to comment 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.