开发者

Send mail through mail relay with PHP

I ran into a wee issue when using mail(). I wasn't able to send to addresses off the domain I was hosting the form. I understand this is for security reasons but it makes the creation of a 'send to friend' system a little tough.

Here's what I had working (albeit it only sent to my address):

<?php

$senderName = $_POST['name'];
$friendsEmail = $_POST['friendsEmail'];

if ($_POST['formName'] == 'refer') {    
    $to = $friendsEmail;
    $subject = "$senderName has referred you";
    $message = "Message goes here";
开发者_StackOverflow社区    $headers = "MIME-Version: 1.0\r\n";
    $headers = "Content-Type: text/html; charset=ISO-8859-1\r\n";
    $headers .= 'From: Me <no-reply@test.com>' . "\r\n";
    mail($to,$subject,$message,$headers);
}

header("Location: referConfirm.html");
?>

I've talked to my hosting company who setup a mail relay (yay!). Trouble is, I have no idea how to get what I working above through a mail relay. I have the following details:

IP: 000.000.000.000 Domain: domain.company.com UN: username PW: password

(Details are dummy.)

Can anyone give me a clue?

Thanks, @rrfive


mail() uses the smtp/sendmail settings found in php.ini. If you need to send it via another smtp, or one with authentication (like in your example) mail is simply not enough.

There are good mailer libraries out there, just to name a few:

  • Swift Mailer
  • Zend_Mail
  • PHPMailer

They are all capable of sending emails via an authenticated smtp server.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜