6

I answered my own question, but I do not know why it got deleted. Apparently a moderator deleted it, so I, as the asker, cannot delete it.

My answer was

Install phpmailer.

Here is a sample on how to send mail with PHP mailer

function smtpmailer($to, $from, $from_name, $subject, $body) { 
  global $error;
  $mail = new PHPMailer();  // create a new object
  $mail->IsSMTP(); // enable SMTP
  $mail->SMTPDebug = 0;  // debugging: 1 = errors and messages, 2 = messages only
  $mail->SMTPAuth = true;  // authentication enabled
  $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
  $mail->Host = 'smtp.gmail.com';
  $mail->Port = 465; 
  $mail->Username = GUSER;  
  $mail->Password = GPWD;           
  $mail->SetFrom($from, $from_name);
  $mail->Subject = $subject;
  $mail->Body = $body;
  $mail->AddAddress($to);
  if(!$mail->Send()) {
      $error = 'Mail error: '.$mail->ErrorInfo; 
      return false;
  } else {
      $error = 'Message sent!';
      return true;
  }
}

Would someone be so kind as to explain what I did wrong?

11

Your question is a troubleshooting one, but the answer appears to be a product recommendation. Your answer would be a better one if it explained specifically why installing PHPMailer is the definitive solution to the problem you posed, rather than fixing your broken code.

  • 8
    The code you copy-pasted also doesn't explain how to use it here on the site. I'm sure a novice user would be confused when they copy-paste that code from your answer and can't figure out what PHP means when it says GUSER and GPWD aren't defined. – animuson Oct 12 '13 at 15:41
  • @animuson Fair point and I appreciate the fast response. But wouldn't have been better for to have left a comment explaining this rather than delete the post? And should I just repost it my answer with more detail? – TAAPSogeking Oct 12 '13 at 16:41
  • 1
    Post an answer that says "This is how I fixed it," and accept the answer. – Robert Harvey Oct 12 '13 at 17:07
  • 3
    @TAAPSogeking I'm the one who deleted, and this is the answer why. It looked like a product recommendation with a broad tutorial, and not a specific answer. I didn't know it was a self answer (I usually don't take that into account), but it seemed... off. :) – Andrew Barber Oct 12 '13 at 19:18
  • @AndrewBarber I had been working on the problem for months, and when I finally found the answer the answer, I wished to post my solution so that others could use it. In the future would you leave some sort of message, but I appreciate your criticism and I hope I have my answer better. – TAAPSogeking Oct 12 '13 at 20:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .