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.

  • 73 Kasutajad peavad seda kasulikuks
Kas see vastus oli kasulik?

Seotud artiklid

General SeekDotNet Mail Server Information

SeekDotNet provides all customers with access to send and receive internet email using their...

What do you mean by Catch All Email?

In short, the catch-all email function allows you to receive all incoming email that is addressed...

What do you mean by Email Forwarding?

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

How do my email address user update their password?

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

I try to send and email throught Outlook but i got the error message "RELAY not allowed" why?

You have to enabled SMTP Authentication **Important - Always use this format username@domain.com...