How to send emails with PHP's mail() function

So I’m using lam-poc to use php and tried the mail() function, but so far none of it works

PHP Code:

// the message
$msg = "First line of text\nSecond line of text";

// use wordwrap() if lines are longer than 70 characters
$msg = wordwrap($msg,70);

// send email
$mail = mail("fnhdiscord@gmail.com","My subject",$msg);
if(mail) {
  echo 'Working!';
}
?>```

I have the same issue, i use this in my glitch.json:

{
  "install": "echo 'We Are Ready!'",
  "start": "php -S 0.0.0.0:3000 -t ."
}

This works for PHP, but when i do:

mail("[redacted]", "logged in", "someone logged in");

it wont send mail

1 Like

Hi, I am having the same problem, after introducing that code to the glitch.json in order to fix the problem with the php redirection page. The mail() function doesn’t work, it is supposedly sent but I don’t receive any email. Have you solved?

Hi! Welcome to the community, @deadshadow99. Please don’t bump old posts: that makes them go to the top of the list! Instead, this kind of post needs a fresh new topic.

1 Like

I don’t believe that the mail() function works, as it does not work with replit either. It probably has to do with the way glitch and replit host your projects on their servers, I assume that they have prevented it because it’s a potential security vulnerability. But can you possibly send the code? also, look into php mailer: https://github.com/PHPMailer/PHPMailer, it might help

1 Like

What Error is it spitting out

Ohh thanks, I will check that later. I will provide the code.

Hi! Try checking out these forum posts as an alternative:

1 Like

I’ll assume Glitch has port 25 (email port) blocked outbound. Check out a tools like sendgrid or mailgun that are web based (and wont get blocked).