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.

Byla tato odpověď nápomocná?

 Tisknout tento článek

Také čtěte

What do you mean by Email Forwarding?

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

What is SPF record and How to enable it?

  SPF provides a way for a domain to tell the world that mail "from" that domain should...

I got Error 554 when send emails from Outlook

How to fix the problem: In Outlook, go to "Tools" and select "Email Accounts". Make sure "View...

How do I send email from ASP using SMTP Authentication in ASP.NET?

Here is the code sample :...

Setup Email in Iphone / Ipad

1.) Go to  Settings >>  Mail, Contacts, Calendars2.) To add a new Email...