PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, July 7, 2022

[FIXED] How can I use phpmailer without composer

 July 07, 2022     php, phpmailer     No comments   

Issue

I need to send emails and the mail() function just does not work for me. The problem is that PHP is not installed on my device. Can I still use it in, index.php for example?

I use 000webhost


Solution

Try this code (it works for me):

<?php

use PHPMailer\PHPMailer\PHPMailer;
require 'PHPMailer.php';
require 'SMTP.php';

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = 'xxx';            // Change here
$mail->Password = 'xxx';            // Change here
$mail->setFrom('xxx', 'Mailer');    // Change here
$mail->addAddress('xxx');           // Change here
$mail->isHTML();
$mail->CharSet = 'utf-8';
$mail->Subject = 'Subject';
$mail->Body = 'Hello world';

echo $mail->Send() ? 'OK!' : 'Something went wrong';

Be sure that:

  • the files PHPMailer.php and SMTP.php are in the same folder of the PHP script (I suggest you to put them all in the root of your website, for now);
  • the PHP script (containing the above code) is UTF-8 encoded.


Answered By - AbsoluteBeginner
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing