Jump to content

Contact Form wthout PHP.ini


jacko310592

Recommended Posts

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

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

	$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....

	$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]");

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

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)

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.