Knowledgebase: Script Mail
Sending E-Mail using PHP
Posted by Paul Woodland on 30 September 2012 03:35 AM
If you are sending mail through PHP on your website, you must use SMTP authentication through our Script Mail service, of which details can be found here:
Due to the PHP developers deciding not to support PHP Authentication in PHP itself, the mail() function can not be used to send email. It provides very limited functionality, and is the most likely to be abused by hackers and spammers, so there are much better options. Any PHP mailer class or script that supports SMTP authentication can be used. We have provided an example below that makes use of the Pear Mail package, which is already available on the servers. You will first need to make sure that you have enabled script mail on your website through the Helm control panel. It will give you host, username and password details to enter into the appropriate places in the script below.

Example of sending email from PHP:

// Include the pear mail package 
require_once "Mail.php"; 

// Set the to address, from address, subject and body
$from = ""
$to = ""
$subject = "Test Message"
$body = "This is a test message"
// Set your script mail details here
$host = ""
$username = "YOUR USERNAME"
$password = "YOUR PASSWORD"

// Set the headers of the message, you to not need to modify this section
$headers = array ('From' => $from, 
'To' => $to, 
'Date' => date('r', time()),
'Subject' => $subject); 

// Set the auth details, you do not need to modify this section
$smtp = Mail::factory('smtp', 
array ('host' => $host, 
'auth' => true, 
'username' => $username, 
'password' => $password)); 

// Send the message, you do not need to modify this section
$mail = $smtp->send($to, $headers, $body); 

// Handle the result, you may wish to change this to your needs
if (PEAR::isError($mail)) { 
echo("Error: " . $mail->getMessage()); 
} else { 
echo("Message Sent"); 
(3 vote(s))
Not helpful

Comments (0)