Knowledgebase: PHP
Can PHP use the mail() Function?
Posted by Arvand Sabetian (Import) on 26 December 2008 08:56 AM

Yes, PHP mail() function can be used to send out mail. PHP mail() function is supported on Linux plans only. The mail() function is not supported on our Windows plans due to the fact that there is no accounting procedure for the emails sent using php sites. Therefore, to make sure abusive accounts are not able to freely send spam emails from our Windows servers, we have disabled the mail() function.

To send mail through PHP on Windows, you can use the Net_SMTP pair package. The documentation is available at: http://pear.php.net/reference/Net_SMTP-1.1.2/li_Net_SMTP.html

Otherwise, we strongly suggest using a linux plan if you plan on deploying applications that require to send mail on php.

(253 vote(s))
Helpful
Not helpful

Comments (33)
Filipi Vaichert de Carvalho
27 October 2010 07:53 PM
How can I use mail() in windows host? have another choice?
Arvand Sabetian
04 November 2010 04:38 AM
Unfortunately, you can not use the mail() function on Windows however you can use PHP's SMTP Class to send mail out by authenticating against the local SMTP server.
Michael Hanon
13 June 2015 06:58 PM
For future users, on windows with PHP, you can use PHPMailer, it is extremely popular and easy. Just google it.
Ryan C
22 June 2015 10:12 PM
As long as PHPMailer supports SMTP authentication, this shouldn't be an issue.
Pablo Villanueva
13 July 2011 02:02 PM
so if I'm ussing the Net_SMTP, how do I make the auth, what method should I use? this isn't working on windflower
Arvand Sabetian
17 July 2011 11:29 PM
You would need to do the PLAIN method.
Richard Taylor-Kenny
22 July 2011 10:57 AM
I have a drupal installation on a Windows Server and have set up the smtp auth module using a gmail account. I had to also get a phpmailer from http://sourceforge.net/projects/phpmailer/ changed the directory name to phpmailer, voila! No problem sending mail.

Decided to try it from site on here and it worked as well

Just used my mail.domain.com server and email address
However could not use ssl What port is SSL on our mail servers?
Arvand Sabetian
25 July 2011 09:00 AM
SSL SMTP is port 465
James Butlin
11 August 2011 12:05 PM
Okay so after three days of trying to brush up on my PHP/CSS, i've come to realise my SMTP problems where because the mail() function isn't supported on my ASP.NET hosting.. Would I be able to swap to a Linux server, and what repercussions (if any) might that result in?
Ryan C
19 October 2011 07:50 AM
Switching between our Windows hosting and Linux is fairly straight forward. You need to download a copy of all of your files and any databases to your own computer, we will terminate the ASP account, and recreate it as Linux where you can reload our files/databases. If you would like to do this, simply get in contact with our sales department via phone, live chat, or email.
Jon Stark
02 May 2012 06:43 AM
I'm using the linux plan and using mail() in my PHP code, but I'm not getting any email out of it. The function returns success, but nothing ever comes through. I tried vaious email addresses, subjects, messages ... What am I missing?
Michael Carr
27 September 2012 10:45 AM
If you can open a support ticket we will be happy to take a look for you. Sounds like something in your code is not correct.
Brian Di Carlo
17 June 2012 02:58 PM
After some scratching around, the following code works for me on the ASP.NET hosting for sending email using PHP;

require_once "Mail.php";
// $from is your Arvixe account
$from = "YourNameHere <[email protected]>";
// $to is the receivers email
$to = "[email protected]";
$subject = "Self Explaining...";

// $host where XXXX is the name of the server where your account is located
$host = "ssl://mail.XXXX.arvixe.com";
$port = "465";
// $username and $password are the uid & pwd of your account
$username = "[email protected]";
$password = "YourPWHere";

$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
// $tok is my prebuilt message body (Ex $tok = "First Name: .$fName."\nMiddle Initial: ".$mName;

$mail = $smtp->send($to, $headers, $tok);

if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}

Michael Carr
10 July 2012 01:19 PM
Thank you for sharing
Yuda Levy
03 September 2012 09:32 PM
Thanks a lot for this code! really helps.

But the Mail::factory() call fails: "Unable to find class for driver smtp".
Didn't you need to install/include/require any other PEAR classes/packages?
Did everything worked just with the above code?

Thanks heaps

Yuda
Michael Carr
25 October 2012 08:08 AM
Mail::factory() may not be setup on all windows servers by default. If you can let us know which server you are on we can certainly get that installed for you. feel free to open a new support ticket by emailing support [at] arvixe.com
Alex Rostko
24 November 2014 06:03 PM
What username password shall I put in there? Is it my billing or WevSitePanel account?
Thanks!
Xan Chin Xao Ju
12 November 2012 06:05 AM
So Where to crab that Mail.php file ? as explained by Brian Di Carlo
Michael Carr
12 November 2012 12:03 PM
In his code, mail.php is the file which is being loaded and contains that example PHP code.
Affan
29 November 2012 10:32 PM
please can anyone guide me, where can I find "Mail.php" file as Brian Di Carlo explained
Michael Carr
30 November 2012 10:47 AM
Please see my response above, In his code, mail.php is the file which is being loaded and contains that example PHP code.
deepak
07 December 2012 04:43 AM
hello sir i hosted my website on shared windows hosting server.
but its mail function not work.as normally we used for linux with mail authentication. so plz help me . with an example
below is my code i used for it
require_once ("Mail.php");
// $from is your Arvixe account
$from = "jack gill <[email protected]>";
// $to is the receivers email
$to = "[email protected]";
$subject = "Self Explaining...";

// $host where XXXX is the name of the server where your account is located
$host = "smtp.gmail.com";
$port = "465";
// $username and $password are the uid & pwd of your account
$username = "[email protected]";
$password = "password";

$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
// $tok is my prebuilt message body (Ex $tok = "First Name: .$fName."\nMiddle Initial: ".$mName;

$mail = $smtp->send($to, $headers, $tok);

if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}

thank you sirftwuu3d
Michael Carr
12 December 2012 07:37 PM
This is sample code provided by another user in the article to send email from the local server. You are trying to use this code to send email through your gmail account which may not work. Please create a support ticket and we will attempt to assist you in relaying email via gmail.
harinder
12 March 2013 09:59 AM
what would be the port number or where can i find port number??
Michael Carr
12 March 2013 12:42 PM
the PHP mail() function does not require a port number, but if you need to connect to the local SMTP server I would suggest using port 25.
Pradeep
21 August 2013 11:12 AM
Hi Sir i have used the same coding but isn't working correctly
Can u please provide me the port number for this mailer
Michael Carr
21 August 2013 11:19 AM
Any mailer sending by SMTP will always use the default SMTP port of 25 unless you are using encryption which would then use port 465.
Mohamed
15 September 2014 08:12 AM
Please make video tutorial for this problem i have WordPress website on windows server and i made contact form to make people send me their enquires, and i used my gmail ( as the email that will receive the enquries from the contact form) and when i tested the contact form i got error "Warning: mail() [function.mail]: SMTP server response: 530 SMTP authentication is required. " please let us know what to do with this problem the link up that you gave it to us is not clear at all
Michael Carr
19 September 2014 01:41 PM
Your problem is not related to this article. Please open a support ticket and we will be happy to look at the setup for you.
raz
13 November 2014 09:39 AM
well, if i dont know how to use Net_SMTP ? in that case What i have to do? and how do we change linux plan?
Michael Carr
28 November 2014 11:52 AM
You would need to order a Linux plan from our site and then migrate over to the new account. There is no simple way to just change the control panel I am afraid.
John Svercek
12 June 2015 07:57 AM
Seems like if mail() is not supported then Arvixe could provide a simple substitute (just change the mail function name in your php code). This code works fine on the provider I am migrating from.
Ryan C
16 June 2015 10:23 PM
If you need to make use of mail(); this requires a Linux hosting plan with us. If you cannot use a Linux hosting plan, than you would need to use SMTP authentication (which I am afraid is not a simple code change as it requires the script to be designed to make use of SMTP authentication rather than just mail alone). Most modern scripts should give you the ability to use both.
Post a new comment
 
 
Full Name:
Email:
Comments:
CAPTCHA Verification 
 
Please enter the text you see in the image into the textbox below (we use this to prevent automated submissions).