mail in php
Posted by: Ares (---.static.as13285.net)
Date: January 30, 2025 11:09PM

I'm trying to use mail in php to generate and send emails. I'm using settings as for Thunderbird (which sends emails OK) with code:

ini_set('SMTP','mail.overssl.net');
ini_set('smtp_port', '465');

ini_set('sendmail_from','rogerkeeling@f2s.com');

$ok=mail($emailTo,$emailSubject,$fullMessage);

but the mail() function just loops indefinitely.

I can run mail.overssl.net on a browser (Chrome) as webmail, but have to enter a password. I can see no way to enter a password in php.

Options: ReplyQuote
Re: mail in php
Posted by: Otomatic (Moderator)
Date: January 31, 2025 08:54AM

See the PHP documentation on this subject:
function mail()

Returns true if the mail was successfully accepted for delivery, false otherwise.

It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination.
It's best to use a class like PHPmailer.

I can't tell you more.

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons

Options: ReplyQuote
Re: mail in php
Posted by: Ares (---.static.as13285.net)
Date: February 14, 2025 08:45PM

Thanks. I've found abundant documentation on the topic. My code is:

$emailTo="myname@f2s.com"; #not actual address

$emailSubject="Email Subject";
$fullMessage="email message";

ini_set('SMTP','smtp.gmail.com');
ini_set('smtp_port', '587');
ini_set('sendmail_from','distrlb@gmail.com'); # not actual address

$errorMessage="";
$_SESSION['errorMessage']=$errorMessage;
$ok=mail($emailTo,$emailSubject,$fullMessage);

if ($ok) {
$errorMessage = "email sent";
} else {
$errorMessage = error_get_last()['message'];
}

When run I get 'Must issue a STARTTLS command first' but cannot find how to run STARTTLS. Can I do this preferably using a line of code in PHP

Options: ReplyQuote
Re: mail in php
Posted by: Otomatic (Moderator)
Date: February 15, 2025 08:37AM

I repeat :

It's best to use a class like PHPmailer. <- this is a link

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons

Options: ReplyQuote
Re: mail in php
Posted by: Ares (---.static.as13285.net)
Date: February 17, 2025 10:08PM

Point taken. I'll work on PHPmailer. Thanks.

Options: ReplyQuote


Sorry, only registered users may post in this forum.