Results 1 to 6 of 6

Thread: Send email Using PHP

  1. #1
    Join Date
    Dec 2008
    Posts
    12

    Send email Using PHP

    Hi Friends,

    How can I send email by using the php code.
    please help me for this.

    Thanks in advance.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Sending a Simple Text Email Using PHP

    PHP includes the mail() function for sending email, which takes three basic and two optional parameters. These parameters are, in order, the email address to send to, the subject of the email, the message to be sent, additional headers you want to include and finally an additional parameter to the Sendmail program. The mail() function returns True if the message is sent successfully and False otherwise.

    Code:
    <?php
    //define the receiver of the email
    $to = 'youraddress@example.com';
    //define the subject of the email
    $subject = 'Test email';
    //define the message to be sent. Each line should be separated with \n
    $message = "Hello World!\n\nThis is my first mail.";
    //define the headers we want passed. Note that they are separated with \r\n
    $headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
    //send the email
    $mail_sent = @mail( $to, $subject, $message, $headers );
    //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 
    echo $mail_sent ? "Mail sent" : "Mail failed";
    ?>

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: Send email Using PHP

    Sending emails via PHP is rather simple with the mail() function.

    mail() function has the following function prototype:

    bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

    Here is an example usage:

    Code:
        $EMAIL_HEADER = “From: Sender Name <sender@example.com>\r\n”;
        $EMAIL_HEADER .= “MIME-Version: 1.0\r\n”;
        $EMAIL_HEADER .= “X-Priority: 1\r\n”;
        $EMAIL_HEADER .= “X-MSmail-Priority: High\r\n”;
    
        $MESSAGE=”
        Hello there,
    
        This is a test message.
    
        From Admin.”;
    
        mail(”recipient@domain.com”, “Example Subject”, $MESSAGE, $EMAIL_HEADER);
    The above code will send out an email to recipient@domain.com with subject “Example Subject” and the message stored in $MESSAGE variable.

    The $EMAIL_HEADER determines that this email will be sent from Sender Name <sender@example.com> and is high priority.

  4. #4
    Nicholas77 Guest

    Re: Send email Using PHP

    Can you send a mail without the need of a smtp server?

  5. #5
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Send email Using PHP

    If you do not have access to an SMTP server or you are having trouble connecting to it, you can use the PHPmailer module as detailed and explained in this Drupal support forum article: http://drupal.org/node/54952
    or using the SMTP class: http://drupal.org/node/29888

  6. #6
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Send email Using PHP

    In theory, if you went to the trouble of finding the recipiants mx record/smtp server, you could use their server to send mail to them, just as a normal smtp server does. Even though you'd have to find the recip's info (their smtp server) on your own, almost any smtp class should be able to handle the actual mail sending.

    In short, the way SMTP works, with relay checks, is that the smtp servers have an open connection. This connection is for both sending mail to other smtp servers and receiving mail from its users and other smtp servers. As long as your email passes the relay checks (using a valid recip email), the remote smtp server should not be able to tell the difference between your script and any other basic smtp server trying to send mail to its user. Some servers may add other checks as well, like aol requires a reverse ip lookup to resolve to a name, but for the most part it should work fine.

    You would just have to figure out the smtp server for each recip on your own before processing the email.

Similar Threads

  1. Replies: 4
    Last Post: 23-08-2011, 08:04 AM
  2. Replies: 6
    Last Post: 10-07-2011, 08:26 PM
  3. Replies: 4
    Last Post: 27-02-2011, 04:32 AM
  4. Windows live mail couldn't send email but can receive email
    By danielyen in forum Windows Software
    Replies: 1
    Last Post: 15-07-2010, 12:17 AM
  5. Replies: 2
    Last Post: 14-02-2008, 09:16 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,006,592.19824 seconds with 16 queries