Skip to content
Sign upLog in
← Back to Community

PHP Mail not working

Profile icon
Coder543

PHP mail() does not seem to be working in repl.it and i have tried it in two repls. I would appreciate help as I have looked over the internet and I am a beginner to PHP. Repl.it error: sh: 1: /usr/sbin/sendmail: not found.
https://repl.it/@Coder543/PHP2#index.php
https://repl.it/@Coder543/PHP1#index.php

Voters
Profile icon
Volodya-Bot-developer
Profile icon
Gloria-BelenBel
Comments
hotnewtop
Profile icon
Coder543

@PattanAhmed
Still the same result :(

Profile icon
PattanAhmed

@Coder543
Hi again,
Please change all the invalid e-mails to your e-mails and try:-

<?php require 'PHPMailerAutoload.php'; $mail = new PHPMailer; $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = '[email protected]'; // SMTP username $mail->Password = 'secret'; // SMTP password $mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted $mail->From = '[email protected]'; $mail->FromName = 'Mailer'; $mail->addAddress('[email protected]', 'Joe User'); // Add a recipient $mail->addAddress('[email protected]'); // Name is optional $mail->addReplyTo('[email protected]', 'Information'); $mail->addCC('[email protected]'); $mail->addBCC('[email protected]'); $mail->WordWrap = 50; // Set word wrap to 50 characters $mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name $mail->isHTML(true); // Set email format to HTML $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'; if(!$mail->send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; } else { echo 'Message has been sent'; }

Hope this helps
Please mark my answer if this helps

Profile icon
PattanAhmed

@Coder543
Hi again,
Check this code:-

<?php $to = '[email protected]'; $subject = 'the subject'; $message = 'hello'; $headers = 'From: [email protected]' . "\r\n" . 'Reply-To: [email protected]' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); ?>

Check this website for more methods (scroll down to see the methods) to send e-mails from PHP
Go from here

Hope this helps
Please mark my answer if this helps

Profile icon
Coder543

@PattanAhmed
I've already tried the one from the second website and I don't understand the first one.

Profile icon
PattanAhmed

@Coder543
You can try with the second one!
It is easy!
Thanks!

Hope this helps
Please mark my answer if this helps

Profile icon
PattanAhmed

@Coder543
Hi,
You can check these two websites to send e-mail from PHP.
Sky-rocket from here to first website.
Second Website

Hope this helps
Please mark my answer if this helps