0

I'm having trouble with a VERY basic php mail bit of code:

<?php
    $email_address  = "test@mydomain.com";
    $subject = "Message yay";

    $email = "test@email.com";
    $message = "huh? " . $email . " this should work";

    //$headers .= "From: 'test' <test@mydomain.com> \n";
    $headers .= "Reply-To: test@mydomain.com \n"; 
    $headers .= "Return-Path: test@mydomain.com \n";
    $headers .= "X-Mailer: PHP/" . phpversion() . "\n"; 
    $headers .= "X-Priority: 1\n";
    //$headers .= "X-MSMail-Priority: High\n";
    $headers .= "MIME-Version: 1.0\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\n";

    mail( $email_address , $subject , $message , $headers);
?>

First off this was working then suddenly didn't after a week or so, So i'm guessing my web host has screwed around with things and not told me. Second I found through trail and error that the two header lines commented out will prevent the email from being sent if they are included (although mail function will return true).

Now here comes the funny part, the code as it is wont send for me either (although mail function will return true), because of the email being inserted in the the message, i wish i could put the email in the reply-to headers but that wont work for me either (although mail function will return true).

Anyway what I really want to know is how do I put the email address in the message in such a way that this will send but also appear as a email address in the message? (because nothing else will work).

I have tired urlencode() which while it works, comes out rather ugly in the email and isn't a solution.

  • PHP's `mail` function should have been deprecated and removed long, long, LONG ago, as it's nearly impossible to use correctly. Please just [`composer require swiftmailer/swiftmailer`](https://packagist.org/packages/swiftmailer/swiftmailer). – Niels Keurentjes Dec 07 '15 at 01:14
  • @NielsKeurentjes yeahhhh... that doesn't look any easier. – Julian Poole Dec 07 '15 at 01:21
  • Mailing isn't easy, you already found that out. But at least with a library like Swiftmailer or PHPMailer it actually works. And both actually are really easy to use if you spend 10 minutes reading their manual. – Niels Keurentjes Dec 07 '15 at 01:22

0 Answers0