mail() not working on my virtual machine - php

Mail() is not working on my virtual machine.
I would like to use it for my php application. What can I do?
What settings should I configure in php.ini to have it work>
I am using sendmail and when I look at the mail logs it tells me "Connection timeout" what can I do?
Also when I do from terminal on my centos server:
telnet smtp.gmail.com 25
it blocks and doesn't output anything.

You need to setup a mail server on your machine for the mail function to work. If you are on Windows (which I am guessing) you can setup a Pegasus mail server. Connecting to either your ISPs SMTP server or GMail or whatever is the easiest route out of this one.
You need to define SMTP settings in your php.ini to talk to a mail server through which you are allowed to send outbound messages, with or without authentication.

If you are working from wamp or xamp then u have to pear mail or some other library to support your configuration. I used pear http://pear.php.net/package/Mail/ ...... it will also contain test mail sending tutorial

Related

Send emails using PHP mail function, configuration of the mail server

I am making a web application (html + php + apache + mysql) which is on a Debian server, but when I try to send any mail using the php mail function, it is not simply sent me and throws an error. I guess I should install some smtp mail service. What do you recommend that is easy for a novice user settings?
I install a library called sendmail in localhost that simulates that smpt service in WAMP server, but when I upload the code to the production server simply does not send mail.
I researched on some mail servers like postfix, but the information I get is confusing to me. I want to recommend me some effective guide, or any server that is easy to configure for a novice user in the subject.
sorry if the question is obvious, but I want effective information
For sending a mail you just simply need a smtp client that sends a mail to a destination. You don't need to install any smtp server for just sending a mail.
A smtp server is for receiving mails( and other stuff about mails).
All you need to make php sending a mail is to install a smtp client like sendmail
then edit php.ini to be like this:
sendmail_path= sendmail -t -i
EDIT: I guess debian has sendmail by default.

My SMTP service is not sending messages to external addresses

I have a local server which host PHP applications. My applications send emails to different addresses. However, I am noticing a problem that I am unable to figure out. It send emails to internal addresses but it won't send messages to external addresses.
I also have an exchange server on the same network. so for example I have these 2 "internal domain"
domain1.com
domain2.com
if I execute this php function from my application it gets delivered with no problem
mail("name#domain1.com","Test Subject","Test message");
However, if I try sening a message to gmail, yahoo or any external domain it does not send it
mail("name#gmail.com","Test Subject","Test message");
My server is running on Windows 2008 Server R2 with PHP5.3.19 installed on it via IIS6
How Can I correct this issue?
mail() on Windows needs extra config in php.ini because Windows does not have Sendmail or anything similar.
The first is the SMTP setting which should point to your ISP's outbound server which is not necessarily the same server that you retrieve your mail from. When I worked in support there were a lot of issues like you describe because an inbound server will still accept mail, but only for the domains that are local to it.
The second is the sendmail_from setting, which is what the gimpy little mailer PHP wrote for the Windows distribution uses in every SMTP transaction regardless of what's in the headers. On *nix Sendmail will read the headers and get the From: address itself, on Windows PHP will always use what's in php.ini. If this is a "garbage" address like example#example.com or something with a non-existant domain many mail servers will reject it outright. What I recommend is to change it to something decent in PHP.ini as well as adding the following line to your mailing scripts:
ini_set('sendmail_from', $from_address);
Alternatively, just use PHPmailer since it simply works much better than PHP's horrid little mail() function.

Mail function - change SMTP relay

I use PHP's mail function to send emails from my server, which currently also handles mail. However, I would like PHP to start sending messages through a different SMTP relay, not the server it's running on. I checked out php.ini, and it appears that it is only possible to specify a different relay on a Windows PC, whilst my server is running OS X Snow Leopard. Is it possible to change the relay settings? Ideally, I wouldn't want to incorporate anything new into my PHP code, as I use the mail function all over the place.
You cannot do this without either setting up a sendmail alternative on your server that routes mail through SMTP, or much much easier, using a library like Swiftmailer.
PHP does not have the capability to use an external SMTP server built in (Unless you are on a Windows platform).

Configure SMTP capabilities on my Apache server

I have an Apache, PHP, MySQL combo running on my Windows 8 machine. I want to send mails using the PHP mail function but then learnt that I need an SMTP server configured. How to do this? I have Outlook installed if that info is of any use.
I used a library called "swiftmail" which can contact an external SMTP server (like gmail) and do the job. Turns out having a local SMTP server wasn't required after all.
Here is the link: http://swiftmailer.org/

Sending mail from own smtp server

I am working for a client who bought a server (V-Server from Strato) with IIS. I've set up a SMTP Server so I can use "mail()" from php to send mails. But everytime I am trying to send a mail, it tells me to configure my SMTP server.
I already added realys, new domains and restarted the whole thing. What can I do? I want to send them from the localhost because the server is running on the machine itself.
First of all, you need to check your mail server (SMTP Server) to confirm it is working properly. To check it manually try telnet 25 port of localhost and execute basic SMTP command to see if it accept mail relaying from your localhost. Microsoft has an article on SMTP check with telnet client, have a look if needed.
If your SMTP server is working as expected, then try debugging your php coding.
FYI: No comments privilege, had to write this as answer...

Categories