$to = "email@example.com"; $subject = "New message from website"; $message = "Hello, this is a test message."; $headers = "From: My Website\r\n"; $headers .= "Reply-To: My Website \r\n"; $headers .= "X-Mailer: PHP/" . phpversion(); mail($to, $subject, $message, $headers);
require 'vendor/autoload.php'; $email = new PHPMailer(true); $email->setFrom('noreply@example.com', 'My Website'); $email->addAddress('email@example.com', 'John Doe'); $email->Subject = 'New message from website'; $email->Body = 'Hello, this is a test message.'; $email->send();
require_once 'lib/swift_required.php'; $transport = Swift_SmtpTransport::newInstance('smtp.example.com', 587) ->setUsername('username') ->setPassword('password'); $mailer = Swift_Mailer::newInstance($transport); $message = Swift_Message::newInstance() ->setSubject('New message from website') ->setFrom(array('noreply@example.com' => 'My Website')) ->setTo(array('email@example.com' => 'John Doe')) ->setBody('Hello, this is a test message.'); $mailer->send($message);The code above uses SwiftMailer library to send an email with a subject of "New message from website".