Slanje mailova preko web strane

Da li imate websajt koji će slati mailove preko kontakt forme, potvrde nadrudžbine itd?
Onda vam preporučujemo da šaljete preko naših SMTP servera umesto da šaljete direktno preko send-email funkcije na web serveru.
Kada šaljete preko naših SMTP servera, to radite kao autorizovani korisnik, čime smanjujete rizik da se vaša poruka vidi kao spam kod primaoca.

Slanje preko PHP-a

Primer koji sledi pokazuje kako da se koristi biblioteka PHPMailer za slanje maila pomoću PHP-a koristeći SMTP servere.PHPMailer možete skinuti ovde.

require 'PHPMailerAutoload.php';

$mail = new PHPMailer;

$mail->isSMTP(); 
$mail->Host = 'mailcluster.loopia.se'; 
$mail->SMTPAuth = true; 
$mail->Username = 'user@example.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; 
$mail->Port = 587;

$mail->From = 'from@example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('joe@example.net', 'Joe User'); // Add a recipient
$mail->addAddress('ellen@example.com'); // Name is optional
$mail->addReplyTo('info@example.com', 'Information');

$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
 echo 'Message could not be sent.';
 echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
 echo 'Message has been sent';
}

Slanje preko .NET-a

Primer koji sledi prikazuje kako da se šalje SSL enkriptovan i HTML formatiran mail preko .NET-a.:

<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.Net.Mail" %>
<%
    MailMessage mail = new MailMessage();
    mail.From = new MailAddress("info@mindoman.se");
    mail.To.Add("min.epost@mindoman.se");
    mail.Subject = "Test av e-post";
    mail.Body = "<em style="color: #f11;">Detta är ett HTML-meddelande.</em>";
    mail.IsBodyHtml = true;
    SmtpClient smtp = new SmtpClient("mailcluster.loopia.se");
    smtp.Credentials = new NetworkCredential("info@mindoman.se", "mittlosenord");
    try
    {
        smtp.Send(mail);
    }
    catch (Exception ex)
    {
        Response.Write("Caught exception: " + ex.ToString());
    }
%>

 

Was this article helpful?

Related Articles