Using offline server in PHP - php

I'm having problems using the mail command in PHP through an offline server.
I've used the mail(to, subject, body) function but the mail wasn't sent to the address. Should I be online?

No, your problem is that you have no SMTP server installed. I suggest you to check on of these:
Pdf tutorial to create your own SMTP Server
Online tutorial
Online tutorial #2
Alternative way to find out
After successfull setting it up, you'll need to configure your php.ini too, to point at the SMTP you are using.
Or instead of creating your own, you can google how to use someone else's SMTP. The choice is yours.

if you are running code from local server then mail function will not send mail. Mail function need live mail server. You can use smtp mail to send mail from local server.

Related

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).

Sending Mail using PHP Mail function - Local mail server?

I am trying to send an e-mail from localhost but am getting the error:
Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set().
Does this mean i need to set up a local mail server?? and if so how and which one is easiest.
Thanks in advance
Paul
This is what I use, but it's for testing purposes only:
http://www.toolheap.com/test-mail-server-tool/
There's almost no configuration, and I got it to work right out of the box (on Win7) after failure with several other mail servers. It does not send the actual mail, but stores it as an .eml file. This is great for testing mailing lists for instance, where you don't really want to send the 2000 emails, but want to get a realistic result from your application.
It might look like garbage, but it's been working great for me.
Yes, it does, and if you want to send mail to an outside email address (and not a user local to the system, it is annoyingly difficult).
Most hosting companies (e.g. GoDaddy) have this setup for you, so PHP's mail() function works without you needing to do anything.
If you're configuring it on your own system, you might want to consider (a) configuring sendmail to use an alternate SMTP gateway (I frequently use Gmail) or (b) a complete alternative to sendmail (Zend Mail looks promising.)
If you are using Linux, there is usually no need to set up a a mail server,
If you are using Windows, yes, you do need to set up a mail server
If you are interested in just sending mail, you can by SMTP protocol use any SMTP server. Here is a tutorial to setting up PHP to use a remote SMTP server.
Yes, you need a mail server to be able to send mail, but even if you do, you are not going to be able to send to addresses outside of you local network as mail from your computer will be blocked by all recipients for spam reasons.
You could use the pear mail function to connect to an external smtp providor like gmail to send the mails for you. More info here and here.
smtp4dev is in my opinion the best tool for capturing local SMTP traffic on Windows.
It listens SMTP on localhost port 25 and pops up a notification every time a new mail is posted (it doesn't actually forward the mail to its recipient). You can then open the message in your favorite mail agent or save it to a file.

PHP mail() not working

I'm building a site on my home computer using MAMP. The code I'm using employs the PHP mail() function to send emails, but whenever I test it, the mails aren't getting sent.
My computer is connected to the net, but I'm wondering if there's something about local hosting that prevents mails from getting sent. I'm not getting any kind of error message.
Any ideas?
PHP can send mail in one of two ways.
The first, and the default on non-Windows systems, is to use the local mail transfer agent installed on the system. This would be "sendmail" or an application compatible with it, the most popular probably being postfix.
The other is to connect via SMTP to some mail server.
You will either need to install a mail transfer agent on your local system (and set it up correctly), or edit PHP's configuration to specify an SMTP server address and port.
Yes, there are things that could block locally hosted mail. For one, your ISP could block SMTP to servers other than the ISP. ask your ISP support if they block SMTP... Or try telexing so someone's MX port 25 and do you get a response?
If your ISP blocks smtp you can still send the mail, but first you must relay that email through a hosted email server like your ISP mail server. This process is called 'smart hosting' and you can search for more info.
Even if you are not blocked on port 25, many sites will refuse or lose smtp traffic that originates from a dynamic or residential IP address, so again the smart host suggestion.
Also I suggest not using the built in mail() function in PHP... Use something that replaces and improves it like http://pear.php.net/package/Mail or http://sourceforge.net/projects/phpmailer/. Again, use the SMTP method as it is way more reliable than direct sending or calling Sendmail.
It is important to confirm this problem, doing SMTP manually over telnet. That way you isolate the problem from PHP. I did ISP support for years and saw this question lots. Most people setup php and mail correctly but get stuck on a background network issue with SMTP.
If you have Wireshark installed, it can record network traffic and you might see the actual SMTP traffic, for example the remote server may be refusing your connection. Wireshark is helpful but not required to solve this though. Good luck.
You need to setup SMTP server in order to be able use mail function, or you can use PHPMailer class, with it you can avoid using mail function and setup problems, PHPMailler need socket extension to be loaded in order to function correctly.

Sending mail via fsockopen?

I know this is possible, but can I do without a remote SMTP server or the like? Basically I want to send mail with PHP, but without mail()
I'm unsure what you exactly mean with 'without a remote SMTP server', as in any mail delivery at least one of those has to be involved - the one receiving mail on account of the recipient...
What you can probably do (it's up to you to decide if it's worth the effort) is to use PHP's socket functions to open a connection on port 25 with a remote mail server. Google 'SMTP telnet' for some examples of how a SMTP session looks like (quite simple, to be true) and then google for 'SMTP codes' for more explanations of what the remote server is saying you.
Possible, but not entirely trivial considering the fact that you should be familiar with SMTP, POP3 and/or IMAP to actually exchange data with a mail server.
You need to code your app so it mimics the behavior of an MTA, that is if you're going to do what the mail() function does - and using sockets. If you're on Linux, another option is to make an OS call to sendmail.
To not use mail() look into PHPMailer
I use this library for all my e-mailing code. I've extended it to have a debug mode so I can intercept outgoing e-mails while testing code.
I could be wrong but you will always be using an SMTP server even if that server is just the webserver with sendmail on it. If you were running your PHP on windows you'd need to enable IIS's in built SMTP service.

How to send email from local machine to gmail?

I am just learning php and it's my first question on this site. Hope, you will help me. I just want to send Email from my local machine to gmail. I have tried but didn't got any success. Please help How to do this.
my code is
form processing
return mail(
$message['to'],
join("\n", $headers))
};
?>
You will want the mail() function see: php.net/manual/en/function.mail.php
mail('kushagra#gmail.com', 'My First Email', 'The body of my email');
You will need a mail server running on your local machine such as Postfix for *nix or Pegasus for Windows.
If you do not have the ability run a mail server on your machine then you might need to use a PHP class that allows you to connect to an SMTP server such as SwiftMailer or PHPMailer.
Be aware though that a lot of ISPs will block connections on port 25 (SMTP) to protect against spamming (see my encounter of this with Optus a few years ago http://blog.simonholywell.com/post/374223466/optus-cable-port-25-smtp). If they are blocking it then you will need to use their SMTP server.
There is a tool linked in my blog post above which will allow you to determine if it is blocked or not see: http://www.zoneedit.com/smtp.html
The standard builtin function to send mail in PHP is mail():
http://php.net/mail
Unfortunately, you cannot use it with Gmail since Gmail requires two security measures that are not supported by good old mail():
Authentication
Encryption
You need to find and download a third-party library. Popular choices include PHPMailer and Swift Mailer.
If you take a look at this PHPMailer example you could use Gmail as an SMTP server to send mail to your own account - guaranteed delivery!

Categories