1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

1人コンプAdvent Calendar 2022

Day 22

phpでメール送信するときに迷惑メール判定されないような関数を作った

Last updated at Posted at 2022-12-23

はじめに

phpでメール送信するには、mb_send_mail();を使うことが多いですが、まれに迷惑メール判定されてしまうことがあります。
そこで、今回は迷惑メール判定されないようなphp自作関数を作ることにしました。

コード

<?php
function send_email($to,$subject,$text,$from_mail,$from_name){
    mb_language('ja');
    mb_internal_encoding('UTF-8');

    $from = $from_name.' <'.$from_mail.'>';
    $header = '';
    $header .= 'Content-Type: text/plain \r\n';
    $header .= 'Return-Path: ' . $from_mail . ' \r\n';
    $header .= 'From: ' . $from .' \r\n';
    $header .= 'Sender: ' . $from .' \r\n';
    $header .= 'Reply-To: ' . $from_mail . ' \r\n';
    $header .= 'Organization: ' . $from_name . ' \r\n';
    $header .= 'X-Sender: ' . $from_mail . ' \r\n';

    if(mb_send_mail( $to, $subject, $text, $header)){
        return true;
    }else{
        return false;
    }
}
?>

使い方

send_email('送信先','件名','内容','送信元メールアドレス','送信者名');
1
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?