how to configure the php mail function with SMTP server? - php

I have used php mail function for sending mail to local mail id's and external mail id's.
using this mail function I am able to send mail to my local mail id's but the mail function is not sending mail to external mail id's. like ss#gmail.com
I have used the following methods to set the SMTP server address.
ini_set("SMTP","net4india.com");
ini_set("sendmail_from","sugumar#csoft.co.in");
and I added with header also
$headers .= "SMTP-Hott:
net4india.com";
but the mail is not going to gmail.
where I need to configure the SMTP server name in my program to send the mail to gmail,yahoo ,hotmail,etc.,?

I have found that using the Pear libraries: Net_SMTP, Mail that you can get better error messages and offers a wider range of options:
http://pear.php.net/package/Net_SMTP
http://pear.php.net/package/Mail
You may want to try using those libraries rather than the built in mail function for php: Demo on how to use Pear Mailer Class

My first recommendation is to use PHPMailer to send email in PHP: http://phpmailer.worxware.com/
Aside from that, I know that google will check SPF DNS records to validate your from address. Here is a wizard that'll help you create an SPF record for your domain: http://old.openspf.org/wizard.html?mydomain=example.com

The MX record for csoft.co.in (64.187.109.136) is gw-mail7.myhsphere.biz (204.10.107.116). So net4india.com (202.71.130.4) would probably reject your e-mail since it doesn't know who you are. In these days of spam you cannot connect to a random mail server and have your e-mail delivered to someone else.
Whatever, net4india.com doesn't even seem to host a SMTP server at all.
To sum up: learn from whoever provides you with mail service for your "#csoft.co.in" account what the SMTP settings are. If you have to provide a password, you cannot use the built-in mail() function at all.

Related

Need Clarification in sending mail to the particular mail address in PHP

i am doing one project. In that project i want to send mail to my customers in php.
presently i am using the sendmailer.php package to sent mail.
Using this package i am sending the mail through my gmail account(i.e, SMTP Protocol).it takes 20 sec-1 min.
here my doubt is...
is it possible to send mails to customers with out using smtp protocol..
i know there is a function called mail()..
but my doubt is..!! is it send my mail to customers..?
please clarify my doubt..
i am stuck here..!!
No, It's not possible without a SMTP.
You have to define your own SMTP server settings that normally your host provides, in the PHP ini file for example, when you use the normal mail() function.
You can change the settings like this:
ini_set("SMTP","smtp.example.com" );
ini_set('sendmail_from', 'user#example.com');

Unable to get emails sent by PHP mail function because of another mail server

I'm created a website with PHP on a Linux web hosting package. Normally I will get emails sent by its contact form that produced by PHP Mail() function. But this time, it is a strange case for me.
My customer company has a mail server. If I send an email via my personal email on Gmail, they will get it on their mail server. But when I send emails via contact form, emails go to webmail on website hosting package.
I've removed all email accounts on this host, also I removed DNS MX record from it, but still I can not receive emails sent by contact form on the company mail server accounts.
How can I solve this problem?
As it seems from your question the webshoting provider is also your email hosting provider. The way you explained the problem leads me to the conclusion that your PHP script uses the mail() function which will internally call the MTA (like sendmail) to send the email.
Now what seems to happen here is that PHP is sending the mail through mail() function which is passing it on to the local MTA (like sendmail) which is checking the local configuration. In the local config it seems to find the recipient domain as a local domain and deliver the mail locally to the user. In this case the email is not even leaving the webhoster's server.
As this is not what you expect, you have 2 possibilities if you do not have influence to the MTA's configuration (what i think you dont have).
I would propose (if possible) to not use the mail() function. There are ready to use SMTP classes which will connect to a SMTP server of your coice to send the email to. In that way you can avoid this problem. You should find something in the PHP Classes Repository.
Send the email to a different domain if possible. That way the MTA has to check DNS and send the email to another SMTP server for delivery.
The first thing to establish is how you are sending emails (sendmail or SMTP). Then, whether your emails are a) not sent at all or b) getting rejected by the destination mail server.
I'd check all available logs (source and destination mail servers and daemons). See if mail() itself is erroring. Try using sendmail/smtp directly.
If its the destination server rejecting the mail based on its spam score, try setting SPF records to enable the web server to send mail legally.
If your email function "mail($to,$subject,$message)" is not working then you need to check the server configuration. Now it is enable or not .
For more details, see here : https://wycks.wordpress.com/2013/10/09/when-phps-mail-function-doesnt-work/

PHP Mailer Class

I use the PHP Mailer Class along with the SMTP extension to send e-mail.
The problem is that the php script sends emails only to YAHOO or GMAIL addresses but when I try to send to blabla#neobee.net, I never receive the email.
There are no error messaged when I send to blabla#neobee.net.
There are a lot of things to be checked before you can send mail from a server.
Many recipient mail servers need something called as spf record to be set at the sender's domain:
www.openspf.org/Introduction
I think , if you are not sending more than 100 mails a day , a better approach would be to use smtp mailer along with google mail
Send email using the GMail SMTP server from a PHP page
So in that way you need not mess or worry about spf or DKIM ..
Its a simple solution but your email would have something#gmail.com that wouldn't be so professional , so if you are looking for professional solution then you need to look for setting up spf records and DKIM for your domain

how to send email from php mail function using gmail account?

I have to send email from my gmail account using php mail() function. I have read the phpmailer but I don't want to include any external apis. Please suggest.
Thanks in advance.
You cannot use mail() to send email with your Gmail account, you'll have to use something that talks to Gmail SMTP server directly. So you're stuck with writing your own or using one of the availiable libraries, the most commonly known are:
Swift Mailer
PHP Mailer
Zend Mail
Assuming mail() works on your server, just:
<?PHP
mail($to,$subj,$body,"From: yourname#gmail.com\r\n");
should do it.
The reason this works is that the "From" address on an email is really very much like the return address on a snail-mail envelope. I can write a letter and mail it from my home, with a return address for my office.

Is it possible with PHP mail to send an email to a specific IP address?

We have a client that can't receive emails from a dedicated server using PHP mail because when their SPAM server does an MX record lookup for the IP it can't find one (so it bounces the email).
This is because the mail exchange is on a different server completely. The client said that they have an IP address that bypasses the SPAM blocker.
So I'm wondering if PHP mail can send an email to a specific IP?
Does your server not qualify as a mail sender by their spam filter? Because I'm guessing that they can receive mail from other people.
So I think you need to look at the setup of your server so it complies with their qualifications (like a reversible name for example, or whatever other rules they require from an email sender)
Because with PHP (and other languages) you just send the email, there are tools that send an email through another server that is qualified to send emails, but usually you use the server itself.
For example, you can use the Zend Mail library to send through another SMTP server.
The answer is yes. However, how the mail() call in PHP actually sends the mail is totally dependent on how your system is set up, so any problems you're having sending mail won't be resolved in your PHP code, they'll be in your mail set up.
Generally, you should be able to address a piece of email to "user#192.168.1.1" and have it arrive successfully.
There's a good article about some of your mailer settings here.

Categories