My code is perfectly fine (but I'll include it at the end anyway) but when I use the in-built php mail() function, and it returns true, I receive no email.
I have read other answers to similar questions but I am still having difficulties with this, seeing as the output log is null and I don't have access (or rather don't know how to access) the php.ini
file. According to the phpinfo() page, it is located at /etc/php55.ini.d/php.ini
but I have no idea where this actually is. I have contacted my provider and they aren't blocking php from sending emails.
So it's a very novice question: how do I access the php.ini
file so I can see if it is configured correctly?
PHP code:
<?php
session_start();
$to = "a valid email";
$subject = "Account Verification";
$message = "Content removed";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <noreply@thefunnyzone.co.uk>' . "\r\n";
$retval = mail ($to,$subject,$message,$header);
if( $retval == true ){echo "Message sent successfully...";}
else{echo "Message could not be sent...";}
?>
I would recommend using PHPMailer ( https://github.com/Synchro/PHPMailer ) . It is much easier to use and is the standard for sending emails with PHP. Visit the github page and see class features to learn more. Below is an example.
require_once("./inc/phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
if (!isset($error_message)) {
$email_body = "";
$email_body = $email_body . "Name: " . $name . "<br>";
$email_body = $email_body . "Email: " . $email . "<br>";
$email_body = $email_body . "Message: " . $message;
$mail->SetFrom($email, $name);
$mail->AddAddress($address, "Joe User");
$mail->Subject = $subject . $name;
$mail->MsgHTML($email_body);
// if the email is sent successfully, redirect to a thank you page;
// otherwise, set a new error message
if($mail->Send()) {
//set success message
} else {
//set error meesage }
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.