Sending emails in PHP using Yahoo SMTP

How can I send an email via Yahoo! SMTP servers in PHP?

+4
source share
4 answers

You should use something like Swift Mailer or PHPMailer . The following example is for Swift:

$message = Swift_Message::newInstance() ->setSubject('Your subject') ->setFrom(array(' john@doe.com ' => 'John Doe')) ->setTo(array(' receiver@domain.org ', ' other@domain.org ' => 'A name')) ->setBody('Here is the message itself') ->addPart('<q>Here is the message itself</q>', 'text/html') ; $transport = Swift_SmtpTransport::newInstance('smtp.mail.yahoo.com', 465, 'ssl') ->setUsername('your username') ->setPassword('your password') ; $mailer = Swift_Mailer::newInstance($transport); $result = $mailer->send($message); 
+2
source

You can use the built-in mail () function to send letters, but it is usually very limited. For example, I do not think that you can use other SMTP servers than the one specified in your php.ini file.

Instead, you should take a look at the Mail PEAR package . For instance:

 <?php require_once "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>"); } ?> 

(I stole this example from http://email.about.com/od/emailprogrammingtips/qt/PHP_Email_SMTP_Authentication.htm : P)

+2
source

Read this http://php.net/manual/en/function.mail.php

 <?php $to = ' nobody@example.com '; $subject = 'the subject'; $message = 'hello'; $headers = 'From: webmaster@example.com ' . "\r\n" . 'Reply-To: webmaster@example.com ' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); ?> 
0
source

The PHP mail program allows you to use any SMTP server that you like if you have login credentials.

0
source

All Articles