1

Afternoon all, I recently set up my own local server doing apache, mysql and php individually as oppose to grabbing the available products out there such as WAMP and XAMPP. I've come across an issue when using the mail() function in php though. That's this:

mail() [function.mail]: "sendmail_from" not set in php.ini

I've tried going into the php.ini file as configuring it but have had no hope. It's come to my understanding that I'm going to need to set up my SMTP? However, I've no idea about how to do this and don't want to go ahead and try without having some knowledge on it first.

Can anyone give me some detailed step by step instructions please on how I can set this up so that my mail() function in php works great within my local server?

Thanks in advance, Rhys

Serge S.
  • 4,855
  • 3
  • 42
  • 46
Rhys Jones
  • 41
  • 2
  • 2
  • 6
  • Your question is so vague. [sendmail_from](http://es1.php.net/manual/en/mail.configuration.php#ini.sendmail-from) is used to set the default "From" e-mail address. What prevented you from editing the `php.ini` file? What does it have to do with the rest of the question? – Álvaro González Oct 03 '13 at 15:06

3 Answers3

4

You are missing From header applied to your message.

You could do it by specifying 4th parameters $headers of mail() function:

$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
       'Reply-To: webmaster@example.com';

mail($to, $subject, $message, $headers);
Serge S.
  • 4,855
  • 3
  • 42
  • 46
  • Hi, thanks for your swift reply. I could do it through the header as you explained, however when I was running it through WAMP it didn't require this parameter. I assume WAMP comes with an SMTP server. The only problem with me doing it this way is that soon it will be uploaded to my company's server and the mail is set in there. If I run the site off the commercial company server the mail works fine. I need an SMTP server for my local server – Rhys Jones Oct 03 '13 at 13:36
  • WAMP comes with preconfigured `sending_from` option in php.ini; This option is automatically pasted to `From` header in `mail()` function, so the issue doesn't appear in WAMP – Serge S. Oct 03 '13 at 13:38
  • Well I basically need a way to do this on my created local server as the code for the header isn't required when I upload it to our hosting server. I'd rather not have to put the code in, then remove it etc. each time I do a site including the mail function – Rhys Jones Oct 03 '13 at 13:41
  • See answer http://stackoverflow.com/a/6941390/301663 how to configure SMTP for `mail()` function. – Serge S. Oct 03 '13 at 13:45
0

I thing you should download the sendmail utility for sending the mail and it will be very easy to configure.

Sendmail download link

  1. download sendmail.zip and unzip its contents
  2. copy sendmail.exe and sendmail.ini to \usr\lib on the drive where the unix application is installed
  3. eg. if your application is installed in c:\bugzilla, sendmail.exe and sendmail.ini need to be copied to c:\usr\lib\sendmail.exe and c:\usr\lib\sendmail.ini. configure smtp server and default domain in sendmail.ini

here sendmail.ini in which you can configure your mail server settings and sending_from, replymail everything in one file.

I hope it is helpful.

Ashwin Parmar
  • 3,025
  • 3
  • 26
  • 42
0

Thanks for the replies everyone. In the end, I figured out I was being silly in the config file for php using wrong syntax. I connected it up with my works SMTP server in the end, so all is good. Thanks for the responses.

Rhys Jones
  • 41
  • 2
  • 2
  • 6