Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 23-01-2009
Member
 
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.
Reply With Quote
  #2  
Old 23-01-2009
Member
 
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";
?>
Reply With Quote
  #3  
Old 23-01-2009
Member
 
Join Date: May 2008
Posts: 2,008
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.
Reply With Quote
  #4  
Old 27-01-2009
Nicholas77
 
Posts: n/a
Re: Send email Using PHP

Can you send a mail without the need of a smtp server?
Reply With Quote
  #5  
Old 28-01-2009
Member
 
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
Reply With Quote
  #6  
Old 28-01-2009
Member
 
Join Date: Feb 2008
Posts: 1,848
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Send email Using PHP"
Thread Thread Starter Forum Replies Last Post
Unable to send email with jpeg's/mp3's attachment to a Verizon phone using Opera's email client Tawannah Technology & Internet 4 23-08-2011 08:04 AM
Unable to send email from email alias via Microsoft Office 365 FrancoL Windows Software 6 10-07-2011 08:26 PM
"send page by email" and "send link by email" disabled in Internet Explorer 8 Bindaas-ER Technology & Internet 4 27-02-2011 04:32 AM
Windows live mail couldn't send email but can receive email danielyen Windows Software 1 15-07-2010 12:17 AM
Cannot send internal email to a external email host like hotmail, gmail, yahoo, gmx etc... Antonio00 Small Business Server 2 14-02-2008 09:16 PM


All times are GMT +5.5. The time now is 04:43 AM.