Skip to content

Instantly share code, notes, and snippets.

@lenn4rd
Created July 17, 2013 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lenn4rd/6023080 to your computer and use it in GitHub Desktop.
Save lenn4rd/6023080 to your computer and use it in GitHub Desktop.
<?php
/* Sends a test email with PHP's mail() method
*
* Put this file on your web server or run it from the command line:
*
* php test_php_mail.php
*
* When testing locally, i.e. on your development machine, make sure that
* you set a valid from address for sendmail unless your machine doesn't
* have a valid, fully qualified domain name (FQDN).
*
* In your php.ini:
*
* sendmail_path = /usr/sbin/sendmail -t -i -f "hello@example.com"
*
* Your mail host will very likely reject mails originating from unknown
* domains such as <your-computer-name.local> since that is where most
* spam mails come from.
*
* Based on: http://www.der-webentwickler.net/php-mysql/mail-versand-unter-php-testen/
*/
$to = "<hello@example.com>";
$subject = "mail() with PHP";
$text = "Lorem ipsum dolor sit amet.";
$headers = "From: $to\r\n";
if (mail($to, $subject, $text, $headers)) {
echo "Email was sent successfully.\n";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment