มันทำได้หมดครับถ้าคุณใช้ hook เป็น
เขียน functions เพิ่มไป 2 ตัวครับ
- hook contact 7 form
add_action( 'wpcf7_mail_sent', 'your_wpcf7_function' );
function your_wpcf7_function( $contact_form ) {
$id = $contact_form->id;
$title = $contact_form->title;
$submission = WPCF7_Submission::get_instance();
$posted_data = array();
if ( $submission ) {
$posted_data = $submission->get_posted_data();
}
$text = "#".$id." - ".$title."\n"."\n";
$text .="You Name: ".$posted_data['your-name']."\n";
$text .="Your Email: ".$posted_data['your-email']."\n";
$text .="Subject: ".$posted_data['your-subject']."\n";
$text .="Your Message: "."\n".$posted_data['your-message']."\n";
// LINE Notify
notify_message($text);
}
- function linenoti
function notify_message($message) {
$line_api = 'https://notify-api.line.me/api/notify';
$line_token = 'your-token';
$queryData = array('message' => $message);
$queryData = http_build_query($queryData,'','&');
$headerOptions = array(
'http'=>array(
'method'=>'POST',
'header'=> "Content-Type: application/x-www-form-urlencoded\r\n"
."Authorization: Bearer ".$line_token."\r\n"
."Content-Length: ".strlen($queryData)."\r\n",
'content' => $queryData
)
);
$context = stream_context_create($headerOptions);
$result = file_get_contents($line_api, FALSE, $context);
$res = json_decode($result);
return $res;
}