PHP Send Emails

« Previous Tutorial Next Tutorial »

PHP must be configured correctly in the file named php.ini with the details of how your system sends email. Open the file php.ini available inside the /etc/ directory and find out the section headed [mail function]

Windows users should ensure that the two directives are supplied. The first is called SMTP that defines your email server address. The second is called sendmail_from which defines your own email address

Here is the configuration for Windows users:

[mail function]
; For Win32 only.

; For win32 only
sendmail_from =

Linux users simply need to let PHP know the location of their sendmail application. The path and any desired switches should be specified to the sendmail_path directive

Here is the configuration for Linux users:

[mail function]
; For Win32 only.

; For win32 only
sendmail_from = 

; For Unix only
sendmail_path = /usr/sbin/sendmail -t -i

Send Plain Text Email using PHP

To send plain text email using PHP, use a function named mail() to sent an email. Here is the general form of mail() function to send an email using PHP:

mail( to, subject, message, headers, parameters );

Here, to represents the receiver's email, subject represents the subject of the email, message represents the actual message which is to be sent, headers represents the additional headers such as from, cc, bcc, and then parameters represents the additional parameter to to the sendmail program.

PHP Send Email Example

Here is an example, shows how to send email using PHP:

	<title>Sending email using PHP</title>
   $to = "";
   $subject = "This is subject";
   $message = "This is simple text message";
   $header = " \r\n";
   $retval = mail ($to,$subject,$message,$header);
   if( $retval == true )  
      echo "Message sent successfully..";
      echo "Message sending failed..";

« Previous Tutorial Next Tutorial »


Quick Links
Signup - Login - Give Online Test