0

So as stated in the title I wanna created a function different from mail to send mail(confusing ik)

So using mail () it sends the email from my server regardless of the headers I put so I need to create a function to send the actual email from a set email

Let's say I have an email

flameforgedinc@gmail.com

Lets say I have a bunch of emails in a mailing list

Now I have some code that's gonna use this function to email each one

So this code use's cMail ($to, $sub, $msg, $from);

And the email will appear to the user

From: flameforgedinc@gmail.com

And I actually want it to come from my email

If I use mail then it comes from my server and displays altervista00000 and I don't want the plus my server limits the mail() function to activation emails and I need to be able to send newsletters

Any ideas or workarounds??

  • i would suggest to use PhpMailer. https://github.com/PHPMailer/PHPMailer – Ashok Chandrapal Oct 12 '16 at 05:22
  • Are you sure you using `mail()` function correctly? Because when I use it and I put from.... doesn't matter if I sending from my host server It is displaying from what email I entered. More information: http://php.net/manual/en/function.mail.php – S.I. Oct 12 '16 at 05:22
  • The actual SMTP `From` header is set by the outgoing MTA, not the `mail()` function. See also http://stackoverflow.com/questions/24644436/php-mail-form-doesnt-complete-sending-e-mail on why that's the least of your worries. – mario Oct 12 '16 at 06:15

1 Answers1

1

My name is Pavel Tashev. I will try to help ;)

The easiest and more correct way from technical point of view is to use your own Mail server which hosts your email account and sends your emails. The purpose of PHP in that cases will be to tell the mail server to send email X to a list of emails Y, from an email account Z.

This will solve all your problems:

  • max allowed emails per hour;
  • sender name;

The good news is that you already have a Gmail account which is hosted by Google and you don't need to build your own mail server. You can use Google's mail server. Also, for the email sending I would advice you to use PHPMailer (url: https://github.com/PHPMailer/PHPMailer).

Here is how we can do all of this. Follow these steps:

  1. Integrate PHPMailer in your project. If you use composer, that will be a straightforward process. If you don't, simply download the code and include this file PHPMailerAutoload.php in your project. Just follow the instructions on Github. It is really easy.
  2. So, when you are ready with the installation of PHPMailer you must tell it to connect to your mail server. For Gmail and your email account this would look like this:

    <?php require 'PHPMailerAutoload.php'; $mail = new PHPMailer; $mail->isSMTP(); $mail->Host = 'smtp.gmail.com'; $mail->SMTPAuth = true; $mail->Username = 'flameforgedinc@gmail.com'; $mail->Password = 'PUT-YOUR-PASSWORD-HERE'; $mail->SMTPSecure = 'tls'; $mail->Port = 587; $mail->setFrom('flameforgedinc@gmail.com', 'YOU CAN PUT YOUR NAMES HERE IF YOU WANT');

  3. The final step is to set up the recipient and the content of the email:

    $mail->addAddress('some.user@example.net', 'Joe User'); $mail->addAddress('seconrd.user@example.com', 'The name is optional'); $mail->addReplyTo('flameforgedinc@gmail.com', 'YOU CAN PUT YOUR NAMES HERE IF YOU WANT'); $mail->isHTML(true);
    $mail->Subject = 'Here is the subject'; $mail->Body = 'This is the HTML message body <b>in bold!</b>'; $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

now you will have to send the email:

!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}

I hope that will help.

Hazonko
  • 1,025
  • 1
  • 15
  • 30
Pavel Tashev
  • 311
  • 1
  • 4
  • 12
  • Yes, it should work. Do you experience any difficulties? – Pavel Tashev Oct 16 '16 at 08:35
  • Yeah phpmailer requires composervice can't use composer on free Web hosting –  Oct 16 '16 at 23:21
  • You don't need composer, Joseph. You can install PHPMailer manually. Do this: (1) Dowdload the code from https://github.com/PHPMailer/PHPMailer and in the file where you want to use PHPMailer simply add this "require 'PHPMailerAutoload.php';". This will make a call to the autoloader of PHPMailer which will include all required files and libraries for you. That's it ;) Try and write me if you have any issues. – Pavel Tashev Oct 18 '16 at 08:16