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");
}
?>
Contact Form to email
Moderator: General Moderators
Re: Contact Form to email
Move the ini_set to before you try sending the mail.
-
alwayslearning
- Forum Newbie
- Posts: 3
- Joined: Sat Oct 01, 2011 11:32 pm
Re: Contact Form to email
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
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
Is your mail server up and running?
-
alwayslearning
- Forum Newbie
- Posts: 3
- Joined: Sat Oct 01, 2011 11:32 pm
Re: Contact Form to email
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
I'm not familiar with XAMPP, but Google has plenty of info.
Re: Contact Form to email
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:
Let me know if that works.
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);
?>
- Kaleb Klein
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156