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.

Ha estat útil la resposta?

 Imprimeix aquest Article

Llegir també

What is the detail for my SMTP and POP3 Server?

If your domain has already pointed to our NameServer, you can just use : mail.yourdomain.com If...

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...

Do you allow Bulk Mail sending?

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

How do my email address user update their password?

Follow this instruction : Log into SeekDotNet webmail (http://mail.yourdomainname.com)...

How to setup email with Outlook 2007?

Configuring your email client: Outlook 2007 Open Outlook 2007. Click...