How to send email using PHP script?

For PHP, We provide pear mail using smtp authentication method , here is the code sample:

<?php

require_once "c:\php\pear\Mail.php";

 

$from = "Sandra Sender <sender@example.com>";

$to = "Ramona Recipient <recipient@example.com>";

$subject = "Hi!";

$body = "Hi,\n\nHow are you?";

 

$host = "mail.example.com";

$username = "smtp_username";

$password = "smtp_password";

 

$headers = array ('From' => $from,

  'To' => $to,

  'Subject' => $subject);

$smtp = Mail::factory('smtp',

  array ('host' => $host,

    'auth' => true,

    'username' => $username,

    'password' => $password));

 

$mail = $smtp->send($to, $headers, $body);

 

if (PEAR::isError($mail)) {

  echo("<p>" . $mail->getMessage() . "</p>");

 } else {

  echo("<p>Message successfully sent!</p>");

 }

?>

Please use your own mail credentials : mail.yourdomain.com as the email host.

Помог ли вам данный ответ?

 Распечатать статью

Также читают

How to increase mailbox size on SmarterMail?

To set or edit the mailbox size for an individual user in SmarterMail: 1.Login to the web...

Instructions for requesting SBC Port 25 Filter Removal

1. Visit the following web site : http://help.sbcglobal.net/servabuse.php 2. You may be prompted...

I could not open email using Outlook or any Mail Client

First, please make sure that your email account is created on our server. You can check this by...

Do you allow Bulk Mail sending?

We strictly do not allow the Bulk Mail sending, we will categorize the bulk mail sending as...

What do you mean by Email Forwarding?

Basically email forwarding allows you to create a unique email account which will...