The steps to send email using PHP (MailGun) code
Step 1. Sign up Mailgun
Step 2. Verify account with Email & Mobile number
Step 3. Find API Base URL & API Key from Domain Information
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
//Sample Code $APIBaseURL="https://api.mailgun.net/v3/sandboxde0a35ca87f94eab90346364e40eab23.mailgun.org"; $APIKey="api:key-8d6da61859417b54bd5f611681adf32d"; $body="Email content"; $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, $APIKey); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_URL, $APIBaseURL); curl_setopt($ch, CURLOPT_POSTFIELDS, array('from' => 'Abc ', 'to' => '<' . $email . '>', 'subject' => 'Forget Password', 'html' => $body)); $result = curl_exec($ch); curl_close($ch); |
- Codeigniter SMTP Mail gun Code
-
123456789101112131415161718192021222324252627<?php$email = "postmaster@sandboxcfee29b705584927b7871234658796.mailgun.org";$this->load->library('email');$config['protocol'] = 'smtp';$config['smtp_host'] = 'ssl://smtp.mailgun.org';$config['smtp_port'] = '465';$config['smtp_timeout'] = '7';$config['smtp_user'] = $email;$config['smtp_pass'] = 'd71fd0ce176af88577123313121';$config['charset'] = 'utf-8';$config['newline'] = "\r\n";$config['mailtype'] = 'html'; // or html$config['validation'] = TRUE; // bool whether to validate email or not$this->email->initialize($config);$this->email->from("from@email.com", 'Fromname');$this->email->to("to@email.com");$this->email->subject("Email Subject");$this->email->message("Email content");$this->email->send();$return['status'] = "1";$return['msg'] = "Successfully sent email";echo json_encode($return);?>
More Stories
How to set EC2 Ubuntu default password
CPU & Memory usage in PHP
Install PHP mcrypt extension on Ubuntu