/    Sign up×
Community /Pin to ProfileBookmark

mail() does not work on localhost apache.

Hello.

I’m trying to fix it but i can’t. I run apache on arch linux with php 7. I’ve installed[URL=”https://wiki.archlinux.org/index.php/Sendmail#Installation”]sendmail smtp[/URL] and the following is my [B]php.ini[/B] configuration:

[CODE]
[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 = [email protected]

; For Unix only. You may supply arguments as well (default: “sendmail -t -i”).
; http://php.net/sendmail-path
sendmail_path = “/usr/sbin/sendmail -t -i”

; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail().
;mail.force_extra_parameters =

; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
mail.add_x_header = Off

; The path to a log file that will log all mail() calls. Log entries include
; the full path of the script, line number, To address and headers.
;mail.log =
; Log mail to syslog (Event Log on Windows).
;mail.log = syslog
[/CODE]

This is the only line which I changed:

[CODE]
; For Unix only. You may supply arguments as well (default: “sendmail -t -i”).
; http://php.net/sendmail-path
sendmail_path = “/usr/sbin/sendmail -t -i”
[/CODE]

When I try this code:

[CODE]<?php

mail(“[email protected]”, “Test”, “just a test”);
echo “Emailed sended successfully!”;

?>[/CODE]

The email never appears in my gmail.
If I upload the php file in a webhosting server the mail is getting received as expected.

I don’t get any log file in [B]/var/log/httpd[/B] or any mail.log in [B]/var/log[/B]

What else can go wrong?
(I did not forgot to restart apache after configuring php.ini)

Thanks.

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmAug 19.2019 — 1 - the echo "email (sent) correctly" is not something you can actually say. The mail function in php really has only a boolean response that doesn't really confirm that the message was sent correctly. And - you don't even check what that response was!

2 - While I'm no expert at the nuances of sending mail, I do know that the function does allow a set of 'headers' as the 4th argument in the call. You do show a commented out 'from' in your .ini example, so your mail call needs that specified in this argument. Your server configuration may have a proper from argument specified in its .ini so that could be why this works in that environment.
Copy linkTweet thisAlerts:
@babaliarisauthorAug 19.2019 — @ginerjm#1607763 The mai() returns 1. The commented 'from' in my php.ini file says is for Windows only. I only changes the unix sendmail_path. At least these are the instructions I found on the internet.
Copy linkTweet thisAlerts:
@ginerjmAug 19.2019 — Did you read the manual on using the mail function? One needs a "from" address and usually it is supplied in the call to mail. Since I didn't see a line in your .ini sample for the from argument, I assumed that there wasn't one being set. Up to you to do it!

As for what the mail call returns - how do you know this to be true? You don't have any code checking for that supposed '1' value.
Copy linkTweet thisAlerts:
@babaliarisauthorAug 19.2019 — @ginerjm#1607768 Dude you don't know the answer and you keep posting gibberish. Anyway I figured it out. I had to configure the mail server to use another external mail service like gmail. The problem was that most mail services like gmail or yahoo, won't accept emails from local domains (they won't even show them as spam, they completely refuse them).

I could not configure sendmail but I managed to do it using postfix by following this guide https://www.howtoforge.com/tutorial/configure-postfix-to-use-gmail-as-a-mail-relay/

My php.ini file was configured just fine.
×

Success!

Help @babaliaris spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...