Test mail script (Authenticated)

Share it:
      php mailscript authenticated
===========================


<?php
$to = 'to adddress';
$subject = 'Mail Script';
$from = 'from address';
$message = 'Test';

$smtpinfo["host"] = "hostname";
$smtpinfo["port"] = "587";
$smtpinfo["auth"] = true;
$smtpinfo["username"] = "username";
$smtpinfo["password"] = "password";

if(mail($to, $subject, $message, "From: $from"))
echo "Mail sent";
else
echo "Mail send failure - message not sent";
?>


    php mailscript authenticated
===========================
<?php
require_once "Mail.php";

$from = "Sandra Sender <sender-address>";
$to = "Ramona Recipient <recipient address>";
$subject = "Hi test mail";
$body = "Hi, mail test";

$host = "localhost";
$username = "username";
$password = "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>");
 }
?>
 

      aspx mailscript authenticated
================================
 

<% @Page Language="C#" %>
<% @Import Namespace="System.Net.Mail" %>
<%
 String from_email_address = "sender address";
 String to_email_address  = "recipient address";
 String smtp_username = "username";
 String smtp_password = "Password";
 String smtp_server = "hostname";
 //create the mail message
 MailMessage mail = new MailMessage();
 //set the addresses
 mail.From = new MailAddress(from_email_address);
 mail.To.Add(to_email_address);
 //set the content
 mail.Subject = "This is an email";
 mail.Body = "this is a test sample body";
 //send the message.
 SmtpClient smtp = new SmtpClient(smtp_server);
 // Using authentication to connect to above smtp server to send email.
 // Replace txtSMTPUser and txtSMTPPass with your appropriate details.
 System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential(smtp_username, smtp_password);
 smtp.UseDefaultCredentials = false;
 smtp.Credentials = SMTPUserInfo;
 smtp.Send(mail);
%>



Share it:

Post A Comment:

0 comments: