Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the requirements to send an email with PHP?

Tags:

php

email

  • I'm developing a Web application with PHP 5.3.3.
  • I want it to send confirmation e-mails automatically.
  • I don't have a domain name yet.
  • I'm using Windows XP.
  • I don't have PEAR's Mail package.
  • I have hMailServer and is the mail server I want to use to send the e-mails.

My questions are:

  1. Can I send e-mails without a domain name? (Is it absolutely necessary? I just want to test the application for the moment.)
  2. If a domain name is necessary, do I also need to host the application with a Web Hosting Service Provider? Can I do it from my computer?(Remember, I just want to test the application.)
  3. Do I absolutely need the PEAR's mail package? or can I simply use the mail() function?

I'm clueless about what I should do. I've made my research, I understand the parts but I can't make sense of the whole, I mean what resources are necessary and how to put it together. I've never developed any application that sends e-mail before. Please, help me.

like image 412
ecantu Avatar asked Jan 20 '11 17:01

ecantu


People also ask

What is the best way to send an email from PHP?

Using the PHP mail() function. PHP's built-in mail() function is one of the simplest ways to send emails directly from the web server itself. It just takes three mandatory parameters: the email address, email subject and message body—and sends it to the recipient.

Does PHP mail require SMTP?

When you use the PHP mail function, you are sending email directly from your web server. This can cause issues if the FROM address isn't set properly or if your email isn't hosted with DreamHost. Sending mail via SMTP is recommended as email is sent from the mail server rather than the web server.

Why is my mail not sending in PHP?

It could be, for example, because you're missing necessary parameters, have typos in your recipient's email address, or need to set up an SMTP relay. Out of all the possible options as to why your PHP mail() isn't sending email, we found that most issues stem from Postfix being configured incorrectly.

Does PHP allow you to send emails directly from a script?

The mail() function allows you to send emails directly from a script.


2 Answers

  1. Yes. You can set your "from" address to whatever you want. (Though note, the recipient server might detect it's forged and reject it.)

  2. You can host from you computer, just make sure your network is not blocking port 25 outbound.

  3. mail() alone will suffice as long as you have a local SMTP server that will handle your messages. (I'm assuming that's what the hMailServer product is.)

like image 120
Alex Howansky Avatar answered Oct 19 '22 08:10

Alex Howansky


First off, if you're running Windows as your server, you need to configure how your e-mails will be sent (SMTP server). Go to this section in your php.ini file. Change localhost to an SMTP server you can use from your network (either the IP address of your hMailServer OR sometimes you need to purchase one to use like http://www.smtp2go.com/).

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25

Second, you use the mail(...) function in php (including the ability to send HTML mail). That's it.

like image 22
nicktacular Avatar answered Oct 19 '22 07:10

nicktacular