1

I am trying to send a confirmation email to people who sign up at my site.

The problem is that the email is being sent from my default cpanel email account (which, according to Hostgator cannot be changed).

I have other email addresses set up in cpanel. Can't I send using one of them?

            // ---------------- SEND MAIL FORM ----------------
            // send e-mail to ...
            $to=$user;
            // Your subject
            $subject="Confirmation link";

            // From
            $header="from: your name <your email>";
            // Your message
            $message="Your confirmation link \r\n";
            $message.="Click on this link to activate your account \r\n";
            $message.="http://mysite.co/confirmation.php?passkey=$confirm_code";
            // send email
            $sentmail = mail($to,$subject,$message,$header);
  • possible duplicate of [Change the sender name php mail instead of sitename@hostname.com](http://stackoverflow.com/questions/8365754/change-the-sender-name-php-mail-instead-of-sitenamehostname-com) – TimWolla Mar 22 '14 at 19:57
  • @TimWolla I don't see them being similar at all. Am I missing something? – emsoff Mar 22 '14 at 19:59

2 Answers2

3

You can change your From email address supposing your desired From address is on the same domain and your ISP and permissions allow. I've never tried it with an email from another domain, and I'd be surprised if that worked. Just put the email you'd like to use as the From address.

But, if you've tried that and it doesn't work, you can also try adding a fifth argument to the mail() function

$sentmail = mail($to,$subject,$message,$header, "-f newemail@email.com");
emsoff
  • 1,585
  • 2
  • 11
  • 16
1

Use a mail class to send an e-mail. The mail() function is not "trusted".

Check out a useful resource here: https://github.com/PHPMailer/PHPMailer

tvkanters
  • 3,519
  • 4
  • 29
  • 45