E-mail activation not working with php mail

Hey guys!

I have the following php mail, which worked previously on my other webhost but I am currently having some difficulties to get the message to be sent through. For some reason, it is sending it to my g-mail but not the message though:

$to = $email;

                                                                  //sender
                                                                  $from = 'pianocourse101@hotmail.com';
                                                                  $fromName = 'PianoCourse101';

                                                                  //email subject
                                                                  $subject = 'Activate your Primer Level Membership Plan!'; 

                                                                  //attachment file path
                                                                  $file = "codexworld.pdf";

                                                                  //email body content
                                                                  $htmlContent = "<h1>Activate your Primer Level Membership Plan!</h1>
                                                                      <p>Dear $first $last, <br />Thank you for registering your Primer Level Membership Plan with PianoCourse101! You are receiving this e-mail because you or someone else claiming to be you has selected a Primer Level Membership Plan \n\nIf you believe that this is a mistake, please send us a ticket with the subject \"How to cancel my Primer Level Membership Plan?\" and allow at least 48 hours before receiving a reply.\n\nHowever, if this is correct, then you must activate your Primer Level Membership Plan by clicking on the link below: \n\n <a href=https://www.pianocourse101.com/activate.php?email=".htmlspecialchars($to)."&activatetoken=".htmlspecialchars($token4).">Click here to activate your Primer Level Membership Plan.</a>\n\nAlternatively, you can use the following token to manually activate your Level 3 Yearly Membership Plan by clicking on the 'Activate Membership\s Section:' \n\nToken:.$token4;
                                                                  </p>";

                                                                  //header for sender info
                                                                  $headers = "From: $fromName"." <".$from.">";

                                                                  //boundary 
                                                                  $semi_rand = md5(time()); 
                                                                  $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 

                                                                  //headers for attachment 
                                                                  $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; 

                                                                  //multipart boundary 
                                                                  $message = "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"UTF-8\"\n" .
                                                                  "Content-Transfer-Encoding: 7bit\n\n" . $htmlContent . "\n\n"; 

                                                                  //preparing attachment
                                                                  if(!empty($file) > 0){
                                                                      if(is_file($file)){
                                                                          $message .= "--{$mime_boundary}\n";
                                                                          $fp =    @fopen($file,"rb");
                                                                          $data =  @fread($fp,filesize($file));

                                                                          @fclose($fp);
                                                                          $data = chunk_split(base64_encode($data));
                                                                          $message .= "Content-Type: application/octet-stream; name=\"".basename($file)."\"\n" . 
                                                                          "Content-Description: ".basename($file)."\n" .
                                                                          "Content-Disposition: attachment;\n" . " filename=\"".basename($file)."\"; size=".filesize($file).";\n" . 
                                                                          "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
                                                                      }
                                                                  }
                                                                  $message .= "--{$mime_boundary}--";
                                                                  $returnpath = "-f" . $from;

                                                                  //send email
                                                                  $mail = mail($to, $subject, $message, $headers, $returnpath); 

                                                                  //email sending status
                                                                  echo $mail?"<h1>Mail sent.</h1>":"<h1>Mail sending failed.</h1>";

You can configure PHPMailer as your needs. This is an example on how to configure PHPMailer with the Gmail SMTP, but you need to replace smtp.gmail.com with smtp.office365.com, username@gmail.com with your email and your password with your Outlook account password. Like so, you have configured Outlook SMTP.

Must I use phpmailer because I thought that the above should work but it is not showing the html content though…

Yes, you must use it until the mail() function is used for activation emails, otherwise you can use either PHPMailer or the mail() function.

so this mail function should work but in my gmail, it looks like this:

If the mail() function doesn’t work for you, you must use the PHPMailer. I and the Admin of InfinityFree recommend downloading the PHPMailer 5.2 from the link that says “example” and copying the link that starts with https and ends with zip and pasting it on the browser bar pressing then ENTER to download it.

I tried it in the past but never understood how to use the autoloader?

Use this link for PHPMailer troubleshooting.

I have extracted the files to the following directory but I think it is wrong… C:\PHPMailer\PHPMailer-5.2-stable… should it just be under C:\PHPMailer?

You need to upload the files using FTP, not on your Local Disk (C:), but with the File Manager!

Yes but I am only up to step 2 of the following steps:

  1. Download PHPMailer: https://github.com/PHPMailer/PHPMailer/archive/5.2-stable.zip
  2. Extract the downloaded zip file on your computer.
  3. Rename the extracted folder to PHPMailer .
  4. Upload the extracted folder to your hosting account with an FTP client of your choice. As always, you should upload the folder to the htdocs folder for the domain you want to use the script on.

I guess it should be C:\PHPMailer?

On the folder where you downloaded the ZIP (e.g. C:\Users\user\Downloads\PHPMailer-5.2-stable.zip), but remove the PHPMailer-5.2-stable.zip on the final folder and then rename the extracted folder to PHPMailer.

Hello!

So just to clarify, my folder should be C:\PHPMailer and all the contents inside it? Therefore, I uploaded my folder to my cpanel at pianocourse101/htdocs/phpmailer correct?

I seem to be having problems using ftp to upload it… always says error but I can do it manually though…

Just to clarify, the folder should be where you downloaded PHPMailer zip. Then use FileZilla with those settings to upload the entire folder:
FTP server: 185.27.134.11
Port: 21
Connection type: Plain FTP (not secure)
Username: you can find it on the Client Area, with the description as “Website for yoursubdomain”, where yoursubdomain can be overwritten with the name you’ve chosen during the creation of the account.
Password: click on the username, then scroll down and click “Show/Hide” to show the password. Then copy it and paste it in FileZilla.
Connect and go to yourdomain/htdocs/ and upload the PHPMailer folder that you’ve renamed there.

Hello

I had saved the files to the following folder : image

Is that correct because in the past, I saved it in the wrong folder and it didn’t work…

Then upload the folder C:\PHPMailer to FTP with the settings listed on here.

thanks… I uploaded it manually and I think it is okay but now I need to set up my credentials…

Use the example provided on here but change smtp.gmail.com with smtp.office365.com, username@gmail.com with your Outlook/Hotmail email address and yourpassword with the password you use to login to the Microsoft account.

Can I leave it with gmail if I am using a gmail account?

Yes, but you need to enable Less Secure Apps from the Google account settings and disable the request for reCAPTCHAs by clicking here with the Google account you want to use.