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 = "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

Link to comment
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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.