How to authenticate contact us form?

Contact us form are widely available in website to help customers/clients contact the website owners with any request or concern. 

To send an email using a contact us form, the email must be authenticated with a username and password. PHP mailer function must be used instead of PHP mai()

Sending Mail from PHP Using SMTP Authentication - Example 

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

Sending Mail from PHP Using SMTP Authentication and SSL Encryption - Example 

<?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 = "ssl://mail.example.com"; 
$port = "465"; 
$username = "smtp_username"; 
$password = "smtp_password"; 
 
$headers = array ('From' => $from, 
  'To' => $to, 
  'Subject' => $subject); 
$smtp = Mail::factory('smtp', 
  array ('host' => $host, 
    'port' => $port, 
    '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>"); 
} 
?> 

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Do I need to register all three domain name extensions:.com,.sa, .net and .org?

You will realize that the expense for domain name registration and support is minor compared to...

How long will it take to register my domain name?

We will process your domain registration order within 24 hours, provided the registration form is...

I just registered my domain but where do I get the password to access it?

We will process your order within 24 hours and add the domain name to your domain panel account...

Questions

Which version of .Net Framework they are supporting? We supported .Net Framework for versions 1,...

SHARED HOSTING

Now that you have decided to host your web site, you might be wondering what the differences are...