How send email

HI everyone, i try to send a email with some information to validate to user, using $http with POST method to PHP script?. There ir another way?.Am new with these. Thanks

There are email-composer plugins, which allows you to open the default mail app on the device directly --> prefill the necessary fields like recipients, subject and so on.

But it depends on the app. Sometimes it looks more professionell if you have a contact form and not jump out of the app

Do you have idea, How I can it see more professional ?. namely, send an email and not open other.
The app could does transaction in the same app.

Okay, then you should build a beautiful contact form. and if this is the case… you need a little backend (like php-script to send the mails).

This is my angular code:

var app = angular.module(‘starter’, [‘ionic’]);

app.controller(‘send_email’,function($scope,$http){

var config = {
    method:'POST',
    url:'http://www.hobbylacuesta.com/correo.php',
    data:'correo=alexis.970991@gmail.com',
    headers:{'Content-Type':'application/x-www-form-urlencoded'}
}

$scope.sendemail = function(){
    var response = $http(config);
    
    response.success(function(data,status){
        console.log('Done');
    });
    
    response.error(function(data,status){
        console.log('Error');
    });
}

});

This es my php file (It is in the server):

<? php

$message = "email: ".$_POST[“correo”];
$message = htmlspecialchars($mensaje);
$message = stripslashes($mensaje);

$to = “alexis.970991@gmail.com”;
$subject = “You have new email”;
$header = “From:alexis.970991@gmail.com”;
$enviar = mail($to,$subject,$message,$header);

?> 

And this is the error.
image

Do you believe could you help me? … Thanks a lot! :grin:

@alexis791 Put this at the top of your PHP file:

<?php header('Access-Control-Allow-Origin: *'); ?>
2 Likes

this is the cross-origin problem, you will not have this on real devices.
–> search for “google chrome disable websecurity” :wink:
or allow all access in your backend like @Devniz says.

2 Likes

You can use the NodeMailer package. There is not need to use php.

1 Like

Hi everyone,
I try to send a email with information, but I don’t want to use user’s native email app. How I can do that.
I read above discussion, but have one more thing, I don’t want to use any back-end, do all things locally.
How can I do that?
Anyone have any idea?

-Thanks

He’ll have the problem if you look closely the response said the server responded with 500. So the script was broken :-).

First of all, you need to install cordova plugin.
$ ionic cordova plugin add cordova-plugin-email-composer
$ npm install --save @ionic-native/email-composer

Are you sure? Do you have an example working?

pls refer this website

hello guys i have used email composer plugin in ionic for a contact form where when i press button it takes me to the mobile mailer and the information is sent but my issue is with the validation the email can also sent with the blank text plzz help me with validation for email composer

this is my code

.html

Enquiry
  <ion-item>
    <ion-label floating>Product Name</ion-label>
    <ion-input type="text"  value="{{productName}}"  disabled></ion-input>
  </ion-item>

  <ion-item>
    <ion-label floating>Name</ion-label>
    <ion-input type="text" name="name" [(ngModel)]="name" required="required" minlength="4" ></ion-input>
  </ion-item>

  <ion-item>
    <ion-label floating>Phone</ion-label>
    <ion-input type="number" name="phoneNumber" [(ngModel)]="phoneNumber" required="required" minlength="10" ></ion-input>
  </ion-item>

  <ion-item>
    <ion-label floating>Place</ion-label>
    <ion-input type="text" name="place" [(ngModel)]="place" required="" minlength="3" ></ion-input>
  </ion-item>

  <ion-item>
    <ion-label floating>Quantity</ion-label>
    <ion-input type="number" name="quantity" [(ngModel)]="quantity" required=""  ></ion-input>
  </ion-item>
  <button type="submit"  ion-button round >Send Enquiry</button>
</ion-list>
<div text-center>
  <ion-toolbar position="bottom">
    <!--<button type="submit"  ion-button round >Send Enquiry</button>-->
  </ion-toolbar>
</div>

.ts

sendEmail(productName, name, phone, place, quantity) {
// alert(‘senemail enter’);

let email = {
  to: 'enquiry@rajamane.in',
  cc: 'sales@rajamane.in',
  bcc: ['avijith.naik@datakue.com', ''],
  attachments: [],
  subject: 'Product Enquiry',
  body: '<p>Product Name: ' + productName + "</p>" +
  '<p>Name:  ' + name + '</p>' +
  '<p>Phone Number: ' + phone + '</p>' +
  '<p>Place: ' + place + '</p>' +
  '<p>Quantity: ' + quantity + '</p>',
  isHtml: true
};
this.emailComposer.open(email);

}

}

hey, @avijith you can disable submit button whenever form is invalid

<form #form="ngForm">
   <ion-list>
  <ion-item>
    <ion-label floating>Product Name</ion-label>
    <ion-input type="text"  value="{{productName}}"  disabled></ion-input>
  </ion-item>

  <ion-item>
    <ion-label floating>Name</ion-label>
    <ion-input type="text" name="name" [(ngModel)]="name" required="required" minlength="4" ></ion-input>
  </ion-item>

  <ion-item>
    <ion-label floating>Phone</ion-label>
    <ion-input type="number" name="phoneNumber" [(ngModel)]="phoneNumber" required="required" minlength="10" ></ion-input>
  </ion-item>

  <ion-item>
    <ion-label floating>Place</ion-label>
    <ion-input type="text" name="place" [(ngModel)]="place" required="" minlength="3" ></ion-input>
  </ion-item>

  <ion-item>
    <ion-label floating>Quantity</ion-label>
    <ion-input type="number" name="quantity" [(ngModel)]="quantity" required=""  ></ion-input>
  </ion-item>
  <button type="submit"  ion-button round [disabled]="form.invalid" >Send Enquiry</button>
</ion-list>
 </form>

@YAsh0011 thank you for the response i have disabled the button for form invalid but its not working

have you tried my code?
because it work for me

thank you @YAsh0011 it worked thank you so much

Hi guys now my issue is not with sending mail its been solved
But my problem is in Database i dont have any idea regarding the database in Ionic how to use it where to view the inserted files through the sqllte

i have a form where the details are sent to mail now i want those files to be saved in database

so pleace suggest me in how to start with this

help me it dont work