简体   繁体   中英

Accept email address from user and send email to that address

public function send_mail() {

    $this->email->from('your@email.com', 'My Name');
    $this->email->to('to@email.com');
    $this->email->cc('cc@email.com');


    $this->email->subject('Email Test');
    $this->email->message('Testing the email class.');

    $this->email->send();

    echo $this->email->print_debugger();

}

i'm trying out the codeigniter email func but i cant seem to receive the test mail, but it saids that it has successfully send the mail but there's none, new to ci so i'm confused about this problem, $this->load->library('email'); is also loaded, anyhelp thanks!

EDIT

ok guys thanks for the answer i have added the ff code and it now works,

$config = Array(
            'protocol' => 'smtp',
            'smtp_host' => 'ssl://smtp.googlemail.com',
            'smtp_port' => 465,
            'smtp_user' => 'your email',
            'smtp_pass' =>  'your password'
            );

Now my question is how will I edit the codes above to accept the "to" email from the user?

okay i did the "to" part already, and its like this

$this->email->to($point->email);

need help again with the "message" part, i need to put data from the user in the "message" part, i tried what i did in the "to" part but it only accepts one item, i need multiple items, thanks

It works fine in my linux server without any $config.

Please read this to set another protocol

In the section where you're calling the function send_mail() , pass the email address and other data as well, as arguments to the function; something like this:

$to = $point->email;
$msg = $point->message; // the message part
$phone = $point->phone; // phone number
$address = $point->address; // postal address
$this->send_email($to, $msg, $phone, $address);

And then slightly modify the send_mail() function as:

// $to_address will contain the value stored in $to, i.e. "abc@def.com" in this case
public function send_mail($to_address, $body_message, $phone_no, $addr) {

    // can make use of extra data like phone number, address in here
    $this->email->from('your@email.com', 'My Name');
    $this->email->to($to_address);
    $this->email->message($body_message);
    .
    .
    .
}

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM