codescracker


php

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.
SMTP = smtp.secureserver.net

; For win32 only
sendmail_from = webmaster@codescracker.com

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.
SMTP = 

; 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:

<html>
<head>
<title>Sending email using PHP</title>
</head>
<body>
<?php
   $to = "xyz@somedomain.com";
   $subject = "This is subject";
   $message = "This is simple text message";
   $header = "From:abc@somedomain.com \r\n";
   $retval = mail ($to,$subject,$message,$header);
   if( $retval == true )  
   {
      echo "Message sent successfully..";
   }
   else
   {
      echo "Message sending failed..";
   }
?>
</body>
</html>

« Previous Tutorial Next Tutorial »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test