Mail can be sent via PHP or Perl using standard mail scripts.
Here are some things to take into consideration when doing so:
- You can customize the email address users will see when you send them a message (for example, From: siteowner@widgetdesigns.com) in your scripting.
- The From: address used in your script must contain your domain name.
- If the From: field is omitted, the server default email address for your account will be used.
- There is a limit of 250 emails per day sent to recipients outside your domain.
- To ensure successful delivery, adding an SPF record to your DNS records is recommended. Learn More.
Here is a sample PHP script you can use to send email. Be sure to change the <EMAIL TO> and <FROM ADDRESS> values to that of valid email accounts.
<html>
<head>
<title>PHP mail() test</title>
</head>
<body>
<?php
$email = "<EMAIL TO>";
$subject = "Test Message";
$msg = "This is a test message";
$headers = "From: <FROM ADDRESS>" . "\r\n";
mail($email,$subject,$msg,$headers);
print "Mail sent to $email";
?>
</body>
</html>
Here is a sample Perl script you can use to send email. You will need to specify the <EMAIL TO> and <FROM ADDRESS> address. The correct file format for the Perl script will be .pl.
Notice that the subject line in the sample script ends with two \n characters. These characters are required to separate the email header from the email body with a blank line. If you're not seeing the body of your email, double-check to make sure these characters are present.
#!/usr/bin/perl
print "Content-type: text/html\n\n";
$title='mail test';
$to ='<EMAIL TO>';
$from= '<FROM ADDRESS>';
$subject='Using Sendmail';
open(MAIL, "|/usr/sbin/sendmail -t");
## Mail Header
print MAIL "To: $to\n";
print MAIL "From: $from\n";
print MAIL "Subject: $subject\n\n";
## Mail Body
print MAIL "This is a test message from Turbify \n";
close(MAIL);
print "<html><head><title>$title<
/title></head>\n<body>\n\n";
## START HTML content
print "<h1>$title</h1>\n";
print "<p>A message has been sent from $from to $to";
## END HTML CONTENT
print "\n\n</body></html>";
See Also: