Reputation: 1299
I'm running a web server using XAMPP. I have using a web form to send emails using PHP scripting. I was wondering, can some tell me why i'm getting this error?
Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in C:\xampp\htdocs\format.php on line 24
Here is my php.ini code, with the relevant part provided:
[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
Here is also my PHP script, just to show you what i coded (I can't see anything wrong with line 24 by the way).
<?php
$to = '[email protected]';
$subject = 'This is from your company';
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$message = <<<EMAIL
Hi! My name is $email
$message
From $name
Oh ya, my email is $email
EMAIL;
$header = '$email';
if($_POST){
mail($to, $subject, $message, $header);
$feedback = 'Thanks for the email';
}
?>
Any suggestions will be appreciated.
Upvotes: 1
Views: 7434
Reputation: 43552
Always set from in the script, don't rely on that php setting...
Start using swiftmailer, you want regret it...
Upvotes: 2
Reputation: 3460
Check the PHP manual on mail:
<?php
$to = '[email protected]';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
You need the FROM headers. http://php.net/manual/en/function.mail.php
Upvotes: 2
Reputation: 14479
Uncomment the sendmail_from setting in the ini file:
sendmail_from = postmaster@localhost
(remove the semicolon from the beginning). You might also change the postmaster@localhost to something you'd actually want people to see as a sender
Upvotes: 3
Reputation: 1460
you need to have a smtp server to send emails from php mail function. try using gmail smtp and script to send mails.
Upvotes: 1