Page 1 of 1

Contact Form to email

Posted: Sat Oct 01, 2011 11:43 pm
by alwayslearning
Hello all. I am a new member to this forum and also new to php. Hopefully this community of programers can help me with my basic needs.

When I submit my form, I recieve this error:
Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in C:\xampp\htdocs\formTest.php on line 23

I get this ^ warning because of this line of code: ini_set ("sendmail_from","myemailaddress@yahoo.com");

Ive read through other forums about my php.ini file and I don't know if i should change any of these defaults. Currently I am testing on localhost but when I get everything running I will put it on my websites server. My question is, how can I get this to send the email through localhost first, and then what setting need to be changed when I decide to put it on a server?

Thanks for any help possible.

My php.ini for the mail()function is this:

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = postmaster@localhost

Just for the heck of it, heres all my php code. its only 30 lines or so.

<?php


if (array_key_exists('send', $_POST)) {
// mail processing script
$to = 'myemailaddress@yahoo.com';
$subject = 'Feedback from form';

// Process the $_POST variables
$name = $_POST['name'];
$email = $_POST['email'];
$comments = $_POST['comments'];

// Build the message
$message = "Name: $name\r\n\r\n";
$message .= "Email: $email\r\n\r\n";
$message .= "Comments: $comments";

// Limit the line length
$message = wordwrap($message, 150);

// Send it
$mailSent = mail($to, $subject, $message);
ini_set ("sendmail_from","myemailaddress@yahoo.com");
}
?>

Re: Contact Form to email

Posted: Sun Oct 02, 2011 11:44 am
by Celauran
Move the ini_set to before you try sending the mail.

Re: Contact Form to email

Posted: Sun Oct 02, 2011 1:11 pm
by alwayslearning
So I moved ini_set('sendmail_from','myemailaddress@yahoo.com'); to the first line in my php block and I recieve this error:

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() in C:\xampp\htdocs\dcservices\send_contact.php on line 26

line 26 is this: $send_contact = mail($to,$message,$header);

any ideas? Thanks

Re: Contact Form to email

Posted: Sun Oct 02, 2011 1:26 pm
by Celauran
Is your mail server up and running?

Re: Contact Form to email

Posted: Tue Oct 04, 2011 6:17 pm
by alwayslearning
How could I check that and if It is not how do I set up it up. I believe i ran a info(); and it said yes but I will do some research until I hear again. Thank you

Re: Contact Form to email

Posted: Tue Oct 04, 2011 6:53 pm
by Celauran
I'm not familiar with XAMPP, but Google has plenty of info.

Re: Contact Form to email

Posted: Tue Oct 04, 2011 7:00 pm
by Pazuzu156
If you are using something such as Yahoo or Gmail, you need to enable SMTP and IMAP settings through their mail settings before you can do that on a local server. XAMPP or not.

Also it would help to have the headers in there too.

Example:

Code: Select all

<?php

$to = "email@domain.com";
$header = "FROM: email@localhost";
$subject = "My Subject";
$message = "This is the message I am sending to you!";

@mail($to,$subject,$message,$header);

?>
Let me know if that works.