Отправка писем на почту PHP
Отправка писем на почту...
Пример:
function sendemail($toname, $toemail, $fromname, $fromemail, $subject, $message, $type = "plain", $cc = "", $bcc = "") {
require_once getcwd()."/Phpmailer.class.php";
$mail = new PHPMailer();
$locale = "ru";
if (file_exists(getcwd()."/language/phpmailer.lang-".$locale.".php")) {
$mail->SetLanguage($locale, getcwd()."/language/");
} else {
$mail->SetLanguage("en", getcwd()."/language/");
}
//$mail->IsMAIL();
$mail->IsSMTP();
$mail->Host = "localhost"; // сервер SMTP
$mail->Port = "25"; // порт SMTP сервера
$mail->SMTPAuth = true;
$mail->Username = "out@site.com"; // логин SMTP сервера
$mail->Password = "1234"; // пароль SMTP сервера
$mail->CharSet = "windows-1251";
$mail->From = $fromemail;
$mail->FromName = $fromname;
$mail->AddAddress($toemail, $toname);
$mail->AddReplyTo($fromemail, $fromname);
if ($cc) {
$cc = explode(", ", $cc);
foreach ($cc as $ccaddress) {
$mail->AddCC($ccaddress);
}
}
if ($bcc) {
$bcc = explode(", ", $bcc);
foreach ($bcc as $bccaddress) {
$mail->AddBCC($bccaddress);
}
}
if ($type == "plain") {
$mail->IsHTML(false);
} else {
$mail->IsHTML(true);
}
$mail->Subject = $subject;
$mail->Body = $message;
if(!$mail->Send()) {
$mail->ErrorInfo;
$mail->ClearAllRecipients();
$mail->ClearReplyTos();
return false;
} else {
$mail->ClearAllRecipients();
$mail->ClearReplyTos();
return true;
}
}
Пример:
echo sendemail("TO", "to@site.com", "From", "from@site.com", "Title of letter", "This is Cool Story");
Скачать:
9.02.2015, 23:13 -
Категория: Статьи » Программирование » PHP