cdub
cdub

Reputation: 25751

Capture PHP Errors from SMTP

I have the following code:

if($result = $this->Email->peopleFollowingEmail($follow['User']['email'], $viewer['User']['fname'].' '.$viewer['User']['lname'], $viewer['User']['username']))
{
    $pf_model->id = $id;
    $pf_model->saveField('sent_email', 1);
}
else
{
    $pf_model->id = $id;
    $pf_model->saveField('email_error', $result);
}

The Email function either will return true or return $errMessage.

How do I store the error message in my db? I think my $result = ... is wrong.

Upvotes: 0

Views: 55

Answers (2)

roirodriguez
roirodriguez

Reputation: 1740

Try,

$result = $this->Email->peopleFollowingEmail($follow['User']['email'], $viewer['User']['fname'].' '.$viewer['User']['lname'], $viewer['User']['username']);
if($result === true)
{
    $pf_model->id = $id;
    $pf_model->saveField('sent_email', 1);
}
else
{
    $pf_model->id = $id;
    $pf_model->saveField('email_error', $result);
}

Upvotes: 2

Daniel
Daniel

Reputation: 31609

If it returns error message and it's a string you are doing it right. If its not a string you need to serialize it before passing it to database using serialize($result) and unserialize($value) when you want to read it back.

Upvotes: 0

Related Questions