Nov 21, 2009

Sending Mail Using PHP's Mail() Function - Send mail from any account 2 any account

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > How-To's and Tutorials > Programming > PHP

Sending Mail Using PHP's Mail() Function - Send mail from any account 2 any account

spotok
hi,
It is possible to send mail from any account to any account using the php's built in mail() function.. for which is very easy to write the coding...

wt you are supposed to do is just pass the parameters like from, to, subject, message .. and attachments if any, and your email will be sent in no time..

as Astahost.com supports the php scripts you can use it if you already have an account here...

==============================================

Example 1. Sending mail.

<?php
mail("joecool@example.com", "My Subject", "Line 1\nLine 2\nLine 3");
?>



If a fourth string argument is passed, this string is inserted at the end of the header. This is typically used to add extra headers. Multiple extra headers are separated with a carriage return and newline.

Note: You must use \r\n to separate headers, although some Unix mail transfer agents replace \n by \r\n automatically (leads to doubling \r if \r\n is used).

Example 2. Sending mail with extra headers.

<?php
mail("nobody@example.com", "the subject", $message,
"From: webmaster@{$_SERVER['SERVER_NAME']}\r\n" .
"Reply-To: webmaster@{$_SERVER['SERVER_NAME']}\r\n" .
"X-Mailer: PHP/" . phpversion());
?>



The additional_parameters parameter can be used to pass an additional parameter to the program configured to use when sending mail using the sendmail_path configuration setting. For example, this can be used to set the envelope sender address when using sendmail with the -f sendmail option. You may need to add the user that your web server runs as to your sendmail configuration to prevent a 'X-Warning' header from being added to the message when you set the envelope sender using this method. Example 3. Sending mail with extra headers and setting an additional command line parameter.

<?php
mail("nobody@example.com", "the subject", $message,
"From: webmaster@{$_SERVER['SERVER_NAME']}", "-fwebmaster@{$_SERVER['SERVER_NAME']}");
?>



Note: This fifth parameter was added in PHP 4.0.5. Since PHP 4.2.3 this parameter is disabled in safe_mode and the mail() function will expose a warning message and return FALSE if you're trying to use it.

You can also use simple string building techniques to build complex email messages. Example 4. Sending complex email.

<?php
/* recipients */
$to = "mary@example.com" . ", " ; // note the comma
$to .= "kelly@example.com";

/* subject */
$subject = "Birthday Reminders for August";

/* message */
$message = '
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';

/* To send HTML mail, you can set the Content-type header. */
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

/* additional headers */
$headers .= "To: Mary <mary@example.com>, Kelly <kelly@example.com>\r\n";
$headers .= "From: Birthday Reminder <birthday@example.com>\r\n";
$headers .= "Cc: birthdayarchive@example.com\r\n";
$headers .= "Bcc: birthdaycheck@example.com\r\n";

/* and now mail it */
mail($to, $subject, $message, $headers);
?>



Note: Make sure you do not have any newline characters in the to or subject, or the mail may not be sent properly.

Note: The to parameter should not be an address in the form of "Something <someone@example.com>". The mail command may not parse this properly while talking with the MTA (Particularly under Windows).

========================================

 

 

 


Comment/Reply (w/o sign-up)

h3lium
awesome. i didn't think you could send mail with php.

Comment/Reply (w/o sign-up)

Houdini
Nearly the entire tutorial can be found here at this PHP Manual page and actually almost verbatim the HTML in Email example if right from the manual. To learn even more then I sould suggest that you download the manual and possibly also get a great free PHP editor like PHP Designer and it will incorperate the manual and do keyword lookup of PHP functions like the PHP mail() and you would learn even more if you use the online book at this link Practical PHP you might even learn more, it is full of examples and covers just about everything including PHP 5 with the support for OOP.

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : sending, mail, phps, mail, function, send, mail, account, 2, account

  1. Calendar And The Date () Function
    Making Math Simple With Modular Arithmetic (0)
  2. Preventing Spam When Using Php's Mail Function
    (11)
    First of all, if this is not the correct place for this topic please an Admin move it accordingly.
    Recently i read at the PHPBuilder.com website this excelent article Preventing spam when using
    PHP's mail function that explains in a very easy way how to avoid spammers send their spam from
    your own server. Generally speaking, almost all websites includes some kind of contact form which
    is used to send emails with the php mail() function, this contact form can be used for a lot of
    purposes like for example to send comments or sugestions, to report problems on you....
  3. Sending Authorised Mail Using Imap_mail Function
    Mailing through imap_mail(). (2)
    hi, if you have an IMAP account then you can send the mail using the imap_mail() function of php.
    it is similar to mail() function but is an authorative way.. because your email account will require
    authorisation while sending an email here goes an example.. ==================================
    imap_mail (PHP 3>= 3.0.14, PHP 4 , PHP 5) imap_mail -- Send an email message Description bool
    imap_mail ( string to, string subject, string message ]]] ) This function allows sending of
    emails with correct handling of Cc and Bcc receivers. Returns TRUE on success or FAL....

    1. Looking for sending, mail, phps, mail, function, send, mail, account, 2, account

See Also,

*SIMILAR VIDEOS*
Searching Video's for sending, mail, phps, mail, function, send, mail, account, 2, account
advertisement



Sending Mail Using PHP's Mail() Function - Send mail from any account 2 any account

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com